1/*
2 * BluezQt - Asynchronous BlueZ wrapper library
3 *
4 * SPDX-FileCopyrightText: 2014-2015 David Rosca <nowrep@gmail.com>
5 *
6 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
7 */
8
9#ifndef BLUEZQT_ADAPTER_H
10#define BLUEZQT_ADAPTER_H
11
12#include <QList>
13#include <QObject>
14#include <QStringList>
15
16#include "bluezqt_export.h"
17#include "types.h"
18
19#include <memory>
20
21namespace BluezQt
22{
23class Device;
24class PendingCall;
25
26/*!
27 * \inmodule BluezQt
28 * \class BluezQt::Adapter
29 * \inheaderfile BluezQt/Adapter
30 *
31 * \brief Bluetooth adapter.
32 *
33 * This class represents a Bluetooth adapter.
34 */
35class BLUEZQT_EXPORT Adapter : public QObject
36{
37 Q_OBJECT
38
39 /*! \property BluezQt::Adapter::ubi */
40 Q_PROPERTY(QString ubi READ ubi)
41 /*! \property BluezQt::Adapter::address */
42 Q_PROPERTY(QString address READ address)
43 /*! \property BluezQt::Adapter::name */
44 Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
45 /*! \property BluezQt::Adapter::systemName */
46 Q_PROPERTY(QString systemName READ systemName NOTIFY systemNameChanged)
47 /*! \property BluezQt::Adapter::adapterClass */
48 Q_PROPERTY(quint32 adapterClass READ adapterClass NOTIFY adapterClassChanged)
49 /*! \property BluezQt::Adapter::powered */
50 Q_PROPERTY(bool powered READ isPowered WRITE setPowered NOTIFY poweredChanged)
51 /*! \property BluezQt::Adapter::discoverable */
52 Q_PROPERTY(bool discoverable READ isDiscoverable WRITE setDiscoverable NOTIFY discoverableChanged)
53 /*! \property BluezQt::Adapter::discoverableTimeout */
54 Q_PROPERTY(quint32 discoverableTimeout READ discoverableTimeout WRITE setDiscoverableTimeout NOTIFY discoverableTimeoutChanged)
55 /*! \property BluezQt::Adapter::pairable */
56 Q_PROPERTY(bool pairable READ isPairable WRITE setPairable NOTIFY pairableChanged)
57 /*! \property BluezQt::Adapter::pairableTimeout */
58 Q_PROPERTY(quint32 pairableTimeout READ pairableTimeout WRITE setPairableTimeout NOTIFY pairableTimeoutChanged)
59 /*! \property BluezQt::Adapter::discovering */
60 Q_PROPERTY(bool discovering READ isDiscovering NOTIFY discoveringChanged)
61 /*! \property BluezQt::Adapter::uuids */
62 Q_PROPERTY(QStringList uuids READ uuids NOTIFY uuidsChanged)
63 /*! \property BluezQt::Adapter::modalias */
64 Q_PROPERTY(QString modalias READ modalias NOTIFY modaliasChanged)
65 /*! \property BluezQt::Adapter::leAdvertisingManager */
66 Q_PROPERTY(LEAdvertisingManagerPtr leAdvertisingManager READ leAdvertisingManager NOTIFY leAdvertisingManagerChanged)
67 /*! \property BluezQt::Adapter::media */
68 Q_PROPERTY(MediaPtr media READ media NOTIFY mediaChanged)
69 /*! \property BluezQt::Adapter::devices */
70 Q_PROPERTY(QList<DevicePtr> devices READ devices)
71
72public:
73 ~Adapter() override;
74
75 /*!
76 * Returns a shared pointer from this.
77 */
78 AdapterPtr toSharedPtr() const;
79
80 /*!
81 * Returns an UBI of the adapter.
82 *
83 * Example UBI: "/org/bluez/hci0"
84 */
85 QString ubi() const;
86
87 /*!
88 * Returns an address of the adapter.
89 *
90 * Example address: "1C:E5:C3:BC:94:7E"
91 */
92 QString address() const;
93
94 /*!
95 * Returns the name of the adapter.
96 */
97 QString name() const;
98
99 /*!
100 * Sets the \a name of the adapter.
101 *
102 * Returns void pending call.
103 */
104 PendingCall *setName(const QString &name);
105
106 /*!
107 * Returns a system name (hostname) of the adapter.
108 */
109 QString systemName() const;
110
111 /*!
112 * Returns a class of the adapter.
113 */
114 quint32 adapterClass() const;
115
116 /*!
117 * Returns whether the adapter is powered on.
118 */
119 bool isPowered() const;
120
121 /*!
122 * Sets the \a powered state of the adapter.
123 *
124 * Returns void pending call.
125 */
126 PendingCall *setPowered(bool powered);
127
128 /*!
129 * Returns whether the adapter is discoverable by other devices.
130 */
131 bool isDiscoverable() const;
132
133 /*!
134 * Sets the \a discoverable state of the adapter.
135 *
136 * Returns void pending call.
137 */
138 PendingCall *setDiscoverable(bool discoverable);
139
140 /*!
141 * Returns the discoverable timeout in seconds of the adapter.
142 *
143 * The discoverable timeout defines how long the adapter stays in
144 * discoverable state after calling setDiscoverable(true).
145 *
146 * Timeout 0 means infinitely.
147 */
148 quint32 discoverableTimeout() const;
149
150 /*!
151 * Sets the discoverable \a timeout of the adapter in seconds.
152 *
153 * Returns void pending call.
154 */
155 PendingCall *setDiscoverableTimeout(quint32 timeout);
156
157 /*!
158 * Returns whether the adapter is pairable with other devices.
159 */
160 bool isPairable() const;
161
162 /*!
163 * Sets the \a pairable state of the adapter.
164 *
165 * Returns void pending call.
166 */
167 PendingCall *setPairable(bool pairable);
168
169 /*!
170 * Returns the pairable timeout in seconds of the adapter.
171 *
172 * The pairable timeout defines how long the adapter stays in
173 * pairable state after calling setPairable(true).
174 *
175 * Timeout 0 means infinitely.
176 */
177 quint32 pairableTimeout() const;
178
179 /*!
180 * Sets the pairable \a timeout of the adapter in seconds.
181 *
182 * Returns void pending call.
183 */
184 PendingCall *setPairableTimeout(quint32 timeout);
185
186 /*!
187 * Returns whether the adapter is discovering for other devices.
188 */
189 bool isDiscovering();
190
191 /*!
192 * Returns UUIDs of supported services by the adapter in uppercase.
193 */
194 QStringList uuids() const;
195
196 /*!
197 * Returns local device ID in modalias format.
198 */
199 QString modalias() const;
200
201 /*!
202 * Returns the GATT manager interface for the adapter.
203 *
204 * Returns null if the adapter has no GATT manager.
205 */
206 GattManagerPtr gattManager() const;
207
208 /*!
209 * Returns the LE advertising manager interface for the adapter.
210 *
211 * Returns null if the adapter has no Bluetooth LE.
212 */
213 LEAdvertisingManagerPtr leAdvertisingManager() const;
214
215 /*!
216 * Returns the media interface for the adapter.
217 *
218 * Returns null if the adapter has no media.
219 */
220 MediaPtr media() const;
221
222 /*!
223 * Returns list of devices known by the adapter.
224 */
225 QList<DevicePtr> devices() const;
226
227 /*!
228 * Returns a device with the specified \a address.
229 *
230 * The \a address follows a scheme similar to "40:79:6A:0C:39:75".
231 *
232 * Returns null if there is no device with the specified address.
233 */
234 DevicePtr deviceForAddress(const QString &address) const;
235
236 /*!
237 * Starts device discovery.
238 *
239 * Possible errors:
240 *
241 * \list
242 * \li PendingCall::NotReady
243 * \li PendingCall::Failed
244 * \endlist
245 *
246 * Returns void pending call.
247 * \sa discoverableTimeout()
248 */
249 PendingCall *startDiscovery();
250
251 /*!
252 * Stops device discovery.
253 *
254 * Possible errors:
255 *
256 * \list
257 * \li PendingCall::NotReady
258 * \li PendingCall::Failed
259 * \li PendingCall::NotAuthorized
260 * \endlist
261 *
262 * Returns void pending call.
263 */
264 PendingCall *stopDiscovery();
265
266 /*!
267 * Removes the specified \a device.
268 *
269 * It will also remove the pairing information.
270 *
271 * Possible errors:
272 *
273 * \list
274 * \li PendingCall::InvalidArguments
275 * \li PendingCall::Failed
276 * \endlist
277 *
278 * Returns void pending call.
279 */
280 PendingCall *removeDevice(DevicePtr device);
281
282 /*!
283 * Sets the discovery \a filter for the caller.
284 *
285 * When this method is called with no filter parameter, the filter is removed.
286 *
287 * For details and available filter options, see the
288 * \l {https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/adapter-api.txt}
289 * {Bluez documentation for Adapter object}.
290 *
291 * Possible errors:
292 *
293 * \list
294 * \li PendingCall::InvalidArguments
295 * \li PendingCall::Failed
296 * \endlist
297 *
298 * Returns void pending call.
299 */
300 PendingCall *setDiscoveryFilter(const QVariantMap &filter);
301
302 /*!
303 * Gets the discovery filters for the caller.
304 *
305 * This returns the available filters that can be given to setDiscoveryFilter.
306 *
307 * For details and available filter options, see the
308 * \l {https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/adapter-api.txt}
309 * {Bluez documentation for Adapter object}.
310 *
311 * Possible errors:
312 *
313 * \list
314 * \li PendingCall::Failed
315 * \endlist
316 *
317 * Returns string list pending call.
318 */
319 PendingCall *getDiscoveryFilters();
320
321Q_SIGNALS:
322 /*!
323 * Indicates that the adapter was removed.
324 */
325 void adapterRemoved(AdapterPtr adapter);
326
327 /*!
328 * Indicates that at least one of the adapter's properties have changed.
329 */
330 void adapterChanged(AdapterPtr adapter);
331
332 /*!
333 * Indicates that adapter's name has changed.
334 */
335 void nameChanged(const QString &name);
336
337 /*!
338 * Indicates that adapter's system name has changed.
339 */
340 void systemNameChanged(const QString &systemName);
341
342 /*!
343 * Indicates that adapter's class has changed.
344 */
345 void adapterClassChanged(quint32 adapterClass);
346
347 /*!
348 * Indicates that adapter's powered state has changed.
349 */
350 void poweredChanged(bool powered);
351
352 /*!
353 * Indicates that adapter's discoverable state has changed.
354 */
355 void discoverableChanged(bool discoverable);
356
357 /*!
358 * Indicates that adapter's discoverable timeout has changed.
359 */
360 void discoverableTimeoutChanged(quint32 timeout);
361
362 /*!
363 * Indicates that adapter's pairable state has changed.
364 */
365 void pairableChanged(bool pairable);
366
367 /*!
368 * Indicates that adapter's pairable timeout has changed.
369 */
370 void pairableTimeoutChanged(quint32 timeout);
371
372 /*!
373 * Indicates that adapter's discovering state has changed.
374 */
375 void discoveringChanged(bool discovering);
376
377 /*!
378 * Indicates that adapter's UUIDs has changed.
379 */
380 void uuidsChanged(const QStringList &uuids);
381
382 /*!
383 * Indicates that adapter's modalias has changed.
384 */
385 void modaliasChanged(const QString &modalias);
386
387 /*!
388 * Indicates that adapter's GATT manager has changed.
389 */
390 void gattManagerChanged(GattManagerPtr gattManager);
391
392 /*!
393 * Indicates that adapter's LE advertising manager has changed.
394 */
395 void leAdvertisingManagerChanged(LEAdvertisingManagerPtr leAdvertisingManager);
396
397 /*!
398 * Indicates that adapter's media has changed.
399 */
400 void mediaChanged(MediaPtr media);
401
402 /*!
403 * Indicates that a new device was added (e.g. found by discovery).
404 */
405 void deviceAdded(DevicePtr device);
406
407 /*!
408 * Indicates that a device was removed.
409 */
410 void deviceRemoved(DevicePtr device);
411
412 /*!
413 * Indicates that at least one of the device's properties has changed.
414 */
415 void deviceChanged(DevicePtr device);
416
417private:
418 BLUEZQT_NO_EXPORT explicit Adapter(const QString &path, const QVariantMap &properties);
419
420 std::unique_ptr<class AdapterPrivate> const d;
421
422 friend class AdapterPrivate;
423 friend class ManagerPrivate;
424 friend class InitAdaptersJobPrivate;
425};
426
427} // namespace BluezQt
428
429#endif // BLUEZQT_ADAPTER_H
430

source code of bluez-qt/src/adapter.h