Dokit
Internal development documentation
Loading...
Searching...
No Matches
pokitdiscoveryagent.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2022-2024 Paul Colby <git@colby.id.au>
2// SPDX-License-Identifier: LGPL-3.0-or-later
3
4/*!
5 * \file
6 * Defines the PokitDiscoveryAgent and PokitDiscoveryAgentPrivate classes.
7 */
8
12
14
15#include <QBluetoothUuid>
16
17/*!
18 * \class PokitDiscoveryAgent
19 *
20 * The PokitDiscoveryAgent class discovers nearby Pokit devices.
21 *
22 * After constructing a PokitDiscoveryAgent object, and subscribing to the relevant signals,
23 * invoke start() to begin discovery.
24 */
25
26/*!
27 * Constructs a new Pokit device discovery agent with \a parent, using \a deviceAdapter for the
28 * search device.
29 */
31 const QBluetoothAddress &deviceAdapter, QObject *parent)
32 : QBluetoothDeviceDiscoveryAgent(deviceAdapter, parent),
33 d_ptr(new PokitDiscoveryAgentPrivate(this))
34{
35
36}
37
38/*!
39 * Constructs a new Pokit device discovery agent with \a parent.
40 */
47
48/*!
49 * \cond internal
50 * Constructs a new Pokit device discovery agent with \a parent, using \a deviceAdapter for the
51 * search device, and private implementation \a d.
52 */
54 PokitDiscoveryAgentPrivate * const d, const QBluetoothAddress &deviceAdapter,
55 QObject * const parent)
56 : QBluetoothDeviceDiscoveryAgent(deviceAdapter, parent), d_ptr(d)
57{
58
59}
60
61/*!
62 * Constructs a new Pokit device discovery agent with \a parent, and private implementation \a d.
63 */
70/// \endcond
71
72/*!
73 * Destroys this PokitDiscoveryAgent object.
74 */
79
80/*!
81 * Starts Pokit device discovery.
82 *
83 * This override simply enforces that \a method must be \c LowEnergyMethod, as all Pokit devices
84 * used Bluetooth Low Energy (BLE).
85 */
93
94/*!
95 * Starts Pokit device discovery.
96 */
98{
100 qCDebug(d->lc).noquote() << tr("Scanning for Bluetooth Low Energy devices.");
102}
103
104/*!
105 * \fn void PokitDiscoveryAgent::pokitDeviceDiscovered(const QBluetoothDeviceInfo &info)
106 *
107 * This signal is emitted when the Pokit device described by \a info is discovered.
108 */
109
110/*!
111 * \fn void PokitDiscoveryAgent::pokitDeviceUpdated(const QBluetoothDeviceInfo &info, QBluetoothDeviceInfo::Fields updatedFields)
112 *
113 * This signal is emitted when the Pokit device described by \a info is updated. The
114 * \a updatedFields flags tell which information has been updated.
115 */
116
117/*!
118 * \cond internal
119 * \class PokitDiscoveryAgentPrivate
120 *
121 * The PokitDiscoveryAgentPrivate class provides private implementation for
122 * PokitDiscoveryAgent.
123 */
124
125/*!
126 * \internal
127 * Constructs a new PokitDiscoveryAgentPrivate object with public implementation \a q.
128 */
130 : q_ptr(q)
131{
134
137
138 #if (QT_VERSION >= QT_VERSION_CHECK(5, 12, 0)) // Signal added in Qt 5.12.
141 #endif
142
143 connect(q,
144 #if (QT_VERSION < QT_VERSION_CHECK(6, 2, 0))
145 QOverload<PokitDiscoveryAgent::Error>::of(&PokitDiscoveryAgent::error),
146 #else
147 &QBluetoothDeviceDiscoveryAgent::errorOccurred,
148 #endif
150
153}
154
155/*!
156 * Handle scan canceled signals, by simply logging the event for diagnostic purposes.
157 */
159{
160 qCDebug(lc).noquote() << tr("Pokit device scan cancelled.");
161}
162
163/*!
164 * Handle deviceDiscovered signals.
165 *
166 * Here we simply check if \a info describes a Pokit device, and if so, emit pokitDeviceDiscovered().
167 */
169{
171 if (!isPokitProduct(info)) return;
172 qCDebug(lc).noquote() << tr(R"(Discovered Pokit device "%1" at %2.)")
173 .arg(info.name(), info.address().toString());
174 Q_EMIT q->pokitDeviceDiscovered(info);
175}
176
177#if (QT_VERSION >= QT_VERSION_CHECK(5, 12, 0)) // Required signal, and Fields, added in Qt 5.12.
178/*!
179 * Handle deviceUpdated signals.
180 *
181 * Here we simply check if \a info describes a Pokit device, and if so, emit pokitDeviceUpdated().
182 *
183 * \since Qt 5.12.0
184 */
186 const QBluetoothDeviceInfo &info, QBluetoothDeviceInfo::Fields updatedFields)
187{
189 if (!isPokitProduct(info)) return;
190 qCDebug(lc).noquote() << tr(R"(Pokit device "%1" at %2 updated with RSSI %3.)")
191 .arg(info.name(), info.address().toString()).arg(info.rssi());
192 Q_EMIT q->pokitDeviceUpdated(info, updatedFields);
193}
194#endif
195
196/*!
197 * Handle scan errors, by simply logging \a error for diagnostic purposes.
198 */
200{
201 qCWarning(lc).noquote() << tr("Pokit device scan error:") << error;
202}
203
204/*!
205 * Handle scan finished signals, by simply logging the event for diagnostic purposes.
206 */
208{
209 qCDebug(lc).noquote() << tr("Pokit device scan finished.");
210}
211
212/// \endcond
The PokitDiscoveryAgentPrivate class provides private implementation for PokitDiscoveryAgent.
void canceled() const
Handle scan canceled signals, by simply logging the event for diagnostic purposes.
PokitDiscoveryAgentPrivate(PokitDiscoveryAgent *const q)
void finished() const
Handle scan finished signals, by simply logging the event for diagnostic purposes.
void error(const QBluetoothDeviceDiscoveryAgent::Error error) const
Handle scan errors, by simply logging error for diagnostic purposes.
void deviceDiscovered(const QBluetoothDeviceInfo &info)
Handle deviceDiscovered signals.
void deviceUpdated(const QBluetoothDeviceInfo &info, QBluetoothDeviceInfo::Fields updatedFields)
Handle deviceUpdated signals.
The PokitDiscoveryAgent class discovers nearby Pokit devices.
PokitDiscoveryAgent(const QBluetoothAddress &deviceAdapter, QObject *parent=nullptr)
Constructs a new Pokit device discovery agent with parent, using deviceAdapter for the search device.
void start()
Starts Pokit device discovery.
virtual ~PokitDiscoveryAgent()
Destroys this PokitDiscoveryAgent object.
PokitDiscoveryAgentPrivate * d_ptr
Internal d-pointer.
Declares the PokitDiscoveryAgent class.
Declares the PokitDiscoveryAgentPrivate class.
Declares the PokitProduct enumeration, and related helper functions.
QTPOKIT_EXPORT bool isPokitProduct(const QBluetoothDeviceInfo &info)
Returns true if info describes a Pokit device.
QString toString() const const
void deviceDiscovered(const QBluetoothDeviceInfo &info)
void deviceUpdated(const QBluetoothDeviceInfo &info, QBluetoothDeviceInfo::Fields updatedFields)
QBluetoothDeviceDiscoveryAgent::Error error() const const
QBluetoothAddress address() const const
QString name() const const
qint16 rssi() const const
Q_EMITQ_EMIT
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QString tr(const char *sourceText, const char *disambiguation, int n)
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
Declares the StatusService class.