1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QLEADVERTISER_BLUEZ_P_H
5#define QLEADVERTISER_BLUEZ_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include "qlowenergyadvertisingdata.h"
19#include "qlowenergyadvertisingparameters.h"
20
21QT_REQUIRE_CONFIG(bluez);
22
23#include "bluez/bluez_data_p.h"
24
25#include <QtCore/qlist.h>
26#include <QtCore/qobject.h>
27
28QT_BEGIN_NAMESPACE
29
30class QLeAdvertiser : public QObject
31{
32 Q_OBJECT
33public:
34 void startAdvertising() { doStartAdvertising(); }
35 void stopAdvertising() { doStopAdvertising(); }
36
37signals:
38 void errorOccurred();
39
40public:
41 QLeAdvertiser(const QLowEnergyAdvertisingParameters &params,
42 const QLowEnergyAdvertisingData &advData,
43 const QLowEnergyAdvertisingData &responseData, QObject *parent)
44 : QObject(parent), m_params(params), m_advData(advData), m_responseData(responseData) {}
45 ~QLeAdvertiser() override;
46
47protected:
48 const QLowEnergyAdvertisingParameters &parameters() const { return m_params; }
49 const QLowEnergyAdvertisingData &advertisingData() const { return m_advData; }
50 const QLowEnergyAdvertisingData &scanResponseData() const { return m_responseData; }
51
52private:
53 virtual void doStartAdvertising() = 0;
54 virtual void doStopAdvertising() = 0;
55
56 const QLowEnergyAdvertisingParameters m_params;
57 const QLowEnergyAdvertisingData m_advData;
58 const QLowEnergyAdvertisingData m_responseData;
59};
60
61struct AdvData;
62struct AdvParams;
63class HciManager;
64
65class QLeAdvertiserBluez : public QLeAdvertiser
66{
67 Q_OBJECT
68public:
69 QLeAdvertiserBluez(const QLowEnergyAdvertisingParameters &params,
70 const QLowEnergyAdvertisingData &advertisingData,
71 const QLowEnergyAdvertisingData &scanResponseData,
72 std::shared_ptr<HciManager> hciManager,
73 QObject *parent = nullptr);
74 ~QLeAdvertiserBluez() override;
75
76private:
77 void doStartAdvertising() override;
78 void doStopAdvertising() override;
79
80 void setPowerLevel(AdvData &advData);
81 void setFlags(AdvData &advData);
82 void setServicesData(const QLowEnergyAdvertisingData &src, AdvData &dest);
83 void setManufacturerData(const QLowEnergyAdvertisingData &src, AdvData &dest);
84 void setLocalNameData(const QLowEnergyAdvertisingData &src, AdvData &dest);
85
86 void queueCommand(QBluezConst::OpCodeCommandField ocf, const QByteArray &advertisingData);
87 void sendNextCommand();
88 void queueAdvertisingCommands();
89 void queueReadTxPowerLevelCommand();
90 void toggleAdvertising(bool enable);
91 void setAdvertisingParams();
92 void setAdvertisingInterval(AdvParams &params);
93 void setData(bool isScanResponseData);
94 void setAdvertisingData();
95 void setScanResponseData();
96 void setWhiteList();
97
98 void handleCommandCompleted(quint16 opCode, quint8 status, const QByteArray &advertisingData);
99 void handleError();
100
101 std::shared_ptr<HciManager> m_hciManager;
102
103 struct Command {
104 Command() {}
105 Command(QBluezConst::OpCodeCommandField ocf, const QByteArray &data) : ocf(ocf), data(data) { }
106 QBluezConst::OpCodeCommandField ocf;
107 QByteArray data;
108 };
109 QList<Command> m_pendingCommands;
110
111 quint8 m_powerLevel;
112 bool m_sendPowerLevel;
113};
114
115QT_END_NAMESPACE
116
117#endif // Include guard.
118

source code of qtconnectivity/src/bluetooth/qleadvertiser_bluez_p.h