Dokit
Internal development documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Pages
pokitdiscoveryagent.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2022-2025 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
18
19/*!
20 * \class PokitDiscoveryAgent
21 *
22 * The PokitDiscoveryAgent class discovers nearby Pokit devices.
23 *
24 * After constructing a PokitDiscoveryAgent object, and subscribing to the relevant signals,
25 * invoke start() to begin discovery.
26 */
27
28/*!
29 * Constructs a new Pokit device discovery agent with \a parent, using \a deviceAdapter for the
30 * search device.
31 */
39
40/*!
41 * Constructs a new Pokit device discovery agent with \a parent.
42 */
49
50/*!
51 * \cond internal
52 * Constructs a new Pokit device discovery agent with \a parent, using \a deviceAdapter for the
53 * search device, and private implementation \a d.
54 */
62
63/*!
64 * Constructs a new Pokit device discovery agent with \a parent, and private implementation \a d.
65 */
72/// \endcond
73
74/*!
75 * Destroys this PokitDiscoveryAgent object.
76 */
81
82/*!
83 * Starts Pokit device discovery.
84 *
85 * This override simply enforces that \a method must be \c LowEnergyMethod, as all Pokit devices
86 * used Bluetooth Low Energy (BLE).
87 */
95
96/*!
97 * Starts Pokit device discovery.
98 */
100{
102 qCDebug(d->lc).noquote() << tr("Scanning for Bluetooth Low Energy devices.");
104}
105
106/*!
107 * \fn void PokitDiscoveryAgent::pokitDeviceDiscovered(const QBluetoothDeviceInfo &info)
108 *
109 * This signal is emitted when the Pokit device described by \a info is discovered.
110 */
111
112/*!
113 * \fn void PokitDiscoveryAgent::pokitDeviceUpdated(const QBluetoothDeviceInfo &info, QBluetoothDeviceInfo::Fields updatedFields)
114 *
115 * This signal is emitted when the Pokit device described by \a info is updated. The
116 * \a updatedFields flags tell which information has been updated.
117 */
118
119/*!
120 * \cond internal
121 * \class PokitDiscoveryAgentPrivate
122 *
123 * The PokitDiscoveryAgentPrivate class provides private implementation for
124 * PokitDiscoveryAgent.
125 */
126
127/*!
128 * \internal
129 * Constructs a new PokitDiscoveryAgentPrivate object with public implementation \a q.
130 */
132 : q_ptr(q)
133{
136
139
140 #if (QT_VERSION >= QT_VERSION_CHECK(5, 12, 0)) // Signal added in Qt 5.12.
143 #endif
144
145 connect(q,
146 #if (QT_VERSION < QT_VERSION_CHECK(6, 2, 0))
147 QOverload<PokitDiscoveryAgent::Error>::of(&PokitDiscoveryAgent::error),
148 #else
149 &QBluetoothDeviceDiscoveryAgent::errorOccurred,
150 #endif
152
155}
156
157/*!
158 * Handle scan canceled signals, by simply logging the event for diagnostic purposes.
159 */
161{
162 qCDebug(lc).noquote() << tr("Pokit device scan cancelled.");
163}
164
165/*!
166 * Handle deviceDiscovered signals.
167 *
168 * Here we simply check if \a info describes a Pokit device, and if so, emit pokitDeviceDiscovered().
169 */
171{
173 if (!isPokitProduct(info)) return;
174 qCDebug(lc).noquote() << tr(R"(Discovered Pokit device "%1" at %2.)")
175 .arg(info.name(), info.address().toString());
176 Q_EMIT q->pokitDeviceDiscovered(info);
177}
178
179#if (QT_VERSION >= QT_VERSION_CHECK(5, 12, 0)) // Required signal, and Fields, added in Qt 5.12.
180/*!
181 * Handle deviceUpdated signals.
182 *
183 * Here we simply check if \a info describes a Pokit device, and if so, emit pokitDeviceUpdated().
184 *
185 * \since Qt 5.12.0
186 */
188 const QBluetoothDeviceInfo &info, QBluetoothDeviceInfo::Fields updatedFields)
189{
191 if (!isPokitProduct(info)) return;
192 qCDebug(lc).noquote() << tr(R"(Pokit device "%1" at %2 updated with RSSI %3.)")
193 .arg(info.name(), info.address().toString()).arg(info.rssi());
194 Q_EMIT q->pokitDeviceUpdated(info, updatedFields);
195}
196#endif
197
198/*!
199 * Handle scan errors, by simply logging \a error for diagnostic purposes.
200 */
202{
203 qCWarning(lc).noquote() << tr("Pokit device scan error:") << error;
204}
205
206/*!
207 * Handle scan finished signals, by simply logging the event for diagnostic purposes.
208 */
210{
211 qCDebug(lc).noquote() << tr("Pokit device scan finished.");
212}
213
214/// \endcond
215
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)
PokitDiscoveryAgent * q_ptr
Internal q-pointer.
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
QBluetoothDeviceDiscoveryAgent(QObject *parent)
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
QObject(QObject *parent)
Q_EMITQ_EMIT
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QObject * parent() const const
QString tr(const char *sourceText, const char *disambiguation, int n)
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
#define QTPOKIT_BEGIN_NAMESPACE
Macro for starting the QtPokit library's top-most namespace (if one is defined).
#define QTPOKIT_END_NAMESPACE
Macro for ending the QtPokit library's top-most namespace (if one is defined).
Declares the StatusService class.