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

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