From a5f362af452555b5aaa4585be82053029e4b25c0 Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Wed, 14 Oct 2015 16:54:47 +0200 Subject: Bluetooth: Introduce API for LE advertising. And provide an implementation for BlueZ. Change-Id: I302aee7c43b77016d9e1e7a0d5bcbf00096abf76 Reviewed-by: Alex Blasche --- src/bluetooth/qlowenergycontroller.h | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'src/bluetooth/qlowenergycontroller.h') diff --git a/src/bluetooth/qlowenergycontroller.h b/src/bluetooth/qlowenergycontroller.h index be729dda..66928da8 100644 --- a/src/bluetooth/qlowenergycontroller.h +++ b/src/bluetooth/qlowenergycontroller.h @@ -38,11 +38,14 @@ #include #include #include +#include #include QT_BEGIN_NAMESPACE +class QLowEnergyAdvertisingParameters; class QLowEnergyControllerPrivate; + class Q_BLUETOOTH_EXPORT QLowEnergyController : public QObject { Q_OBJECT @@ -53,7 +56,8 @@ public: UnknownRemoteDeviceError, NetworkError, InvalidBluetoothAdapterError, - ConnectionError + ConnectionError, + AdvertisingError, }; Q_ENUM(Error) @@ -63,7 +67,8 @@ public: ConnectedState, DiscoveringState, DiscoveredState, - ClosingState + ClosingState, + AdvertisingState, }; Q_ENUM(ControllerState) @@ -73,6 +78,9 @@ public: }; Q_ENUM(RemoteAddressType) + enum Role { CentralRole, PeripheralRole }; + Q_ENUM(Role) + explicit QLowEnergyController(const QBluetoothAddress &remoteDevice, QObject *parent = 0); // TODO Qt 6 remove ctor explicit QLowEnergyController(const QBluetoothDeviceInfo &remoteDevice, @@ -80,6 +88,11 @@ public: explicit QLowEnergyController(const QBluetoothAddress &remoteDevice, const QBluetoothAddress &localDevice, QObject *parent = 0); // TODO Qt 6 remove ctor + + static QLowEnergyController *createCentral(const QBluetoothDeviceInfo &remoteDevice, + QObject *parent = 0); + static QLowEnergyController *createPeripheral(QObject *parent = 0); + ~QLowEnergyController(); QBluetoothAddress localAddress() const; @@ -100,9 +113,16 @@ public: QLowEnergyService *createServiceObject( const QBluetoothUuid &service, QObject *parent = 0); + void startAdvertising(const QLowEnergyAdvertisingParameters ¶meters, + const QLowEnergyAdvertisingData &advertisingData, + const QLowEnergyAdvertisingData &scanResponseData = QLowEnergyAdvertisingData()); + void stopAdvertising(); + Error error() const; QString errorString() const; + Role role() const; + Q_SIGNALS: void connected(); void disconnected(); @@ -113,6 +133,8 @@ Q_SIGNALS: void discoveryFinished(); private: + explicit QLowEnergyController(QObject *parent = 0); // For the peripheral role. + Q_DECLARE_PRIVATE(QLowEnergyController) QLowEnergyControllerPrivate *d_ptr; }; @@ -122,5 +144,6 @@ QT_END_NAMESPACE Q_DECLARE_METATYPE(QLowEnergyController::Error) Q_DECLARE_METATYPE(QLowEnergyController::ControllerState) Q_DECLARE_METATYPE(QLowEnergyController::RemoteAddressType) +Q_DECLARE_METATYPE(QLowEnergyController::Role) #endif // QLOWENERGYCONTROLLER_H -- cgit v1.2.3