diff options
author | Christian Kandeler <christian.kandeler@theqtcompany.com> | 2015-10-14 16:54:47 +0200 |
---|---|---|
committer | Alex Blasche <alexander.blasche@theqtcompany.com> | 2015-11-17 15:40:02 +0000 |
commit | a5f362af452555b5aaa4585be82053029e4b25c0 (patch) | |
tree | eae7edea0537c8fe55226628fc3d5618741cf04f /src/bluetooth/qlowenergyadvertisingparameters.h | |
parent | eb59027d32c7904a129b16c786df1dc2097ab9c9 (diff) | |
download | qtconnectivity-a5f362af452555b5aaa4585be82053029e4b25c0.tar.gz |
Bluetooth: Introduce API for LE advertising.
And provide an implementation for BlueZ.
Change-Id: I302aee7c43b77016d9e1e7a0d5bcbf00096abf76
Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
Diffstat (limited to 'src/bluetooth/qlowenergyadvertisingparameters.h')
-rw-r--r-- | src/bluetooth/qlowenergyadvertisingparameters.h | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/src/bluetooth/qlowenergyadvertisingparameters.h b/src/bluetooth/qlowenergyadvertisingparameters.h new file mode 100644 index 00000000..8d98a10b --- /dev/null +++ b/src/bluetooth/qlowenergyadvertisingparameters.h @@ -0,0 +1,111 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the QtBluetooth module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QLOWENERGYADVERTISINGPARAMETERS_H +#define QLOWENERGYADVERTISINGPARAMETERS_H + +#include <QtBluetooth/qbluetoothglobal.h> +#include <QtBluetooth/qbluetoothaddress.h> +#include <QtBluetooth/qlowenergycontroller.h> +#include <QtCore/qlist.h> +#include <QtCore/qshareddata.h> + +QT_BEGIN_NAMESPACE + +class QLowEnergyAdvertisingParametersPrivate; + +class Q_BLUETOOTH_EXPORT QLowEnergyAdvertisingParameters +{ + friend Q_BLUETOOTH_EXPORT bool operator==(const QLowEnergyAdvertisingParameters &p1, + const QLowEnergyAdvertisingParameters &p2); +public: + QLowEnergyAdvertisingParameters(); + QLowEnergyAdvertisingParameters(const QLowEnergyAdvertisingParameters &other); + ~QLowEnergyAdvertisingParameters(); + + QLowEnergyAdvertisingParameters &operator=(const QLowEnergyAdvertisingParameters &other); + + enum Mode { AdvInd = 0x0, AdvScanInd = 0x2, AdvNonConnInd = 0x3 }; + void setMode(Mode mode); + Mode mode() const; + + struct AddressInfo { + AddressInfo(const QBluetoothAddress &addr, QLowEnergyController::RemoteAddressType t) + : address(addr), type(t) {} + AddressInfo() {} + + QBluetoothAddress address; + QLowEnergyController::RemoteAddressType type; + }; + enum FilterPolicy { + IgnoreWhiteList = 0x00, + UseWhiteListForScanning = 0x01, + UseWhiteListForConnecting = 0x02, + UseWhiteListForScanningAndConnecting = 0x03, + }; + void setWhiteList(const QList<AddressInfo> &whiteList, FilterPolicy policy); + QList<AddressInfo> whiteList() const; + FilterPolicy filterPolicy() const; + + void setInterval(quint16 minimum, quint16 maximum); + int minimumInterval() const; + int maximumInterval() const; + + // TODO: own address type + // TODO: For ADV_DIRECT_IND: peer address + peer address type + + void swap(QLowEnergyAdvertisingParameters &other) Q_DECL_NOTHROW { qSwap(d, other.d); } + +private: + QSharedDataPointer<QLowEnergyAdvertisingParametersPrivate> d; +}; + +inline bool operator==(const QLowEnergyAdvertisingParameters::AddressInfo &ai1, + const QLowEnergyAdvertisingParameters::AddressInfo &ai2) +{ + return ai1.address == ai2.address && ai1.type == ai2.type; +} + +Q_BLUETOOTH_EXPORT bool operator==(const QLowEnergyAdvertisingParameters &p1, + const QLowEnergyAdvertisingParameters &p2); +inline bool operator!=(const QLowEnergyAdvertisingParameters &p1, + const QLowEnergyAdvertisingParameters &p2) +{ + return !(p1 == p2); +} + +Q_DECLARE_SHARED(QLowEnergyAdvertisingParameters) + +QT_END_NAMESPACE + +#endif // Include guard |