BluezQt

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

KDE's Doxygen guidelines are available online.