File indexing completed on 2025-01-19 06:44:34
0001 /* 0002 * BluezQt - Asynchronous BlueZ wrapper library 0003 * 0004 * SPDX-FileCopyrightText: 2014-2015 David Rosca <nowrep@gmail.com> 0005 * 0006 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0007 */ 0008 0009 #ifndef BLUEZQT_ADAPTER_H 0010 #define BLUEZQT_ADAPTER_H 0011 0012 #include <QList> 0013 #include <QObject> 0014 #include <QStringList> 0015 0016 #include "bluezqt_export.h" 0017 #include "types.h" 0018 0019 #include <memory> 0020 0021 namespace BluezQt 0022 { 0023 class Device; 0024 class PendingCall; 0025 0026 /** 0027 * @class BluezQt::Adapter adapter.h <BluezQt/Adapter> 0028 * 0029 * Bluetooth adapter. 0030 * 0031 * This class represents a Bluetooth adapter. 0032 */ 0033 class BLUEZQT_EXPORT Adapter : public QObject 0034 { 0035 Q_OBJECT 0036 0037 Q_PROPERTY(QString ubi READ ubi) 0038 Q_PROPERTY(QString address READ address) 0039 Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) 0040 Q_PROPERTY(QString systemName READ systemName NOTIFY systemNameChanged) 0041 Q_PROPERTY(quint32 adapterClass READ adapterClass NOTIFY adapterClassChanged) 0042 Q_PROPERTY(bool powered READ isPowered WRITE setPowered NOTIFY poweredChanged) 0043 Q_PROPERTY(bool discoverable READ isDiscoverable WRITE setDiscoverable NOTIFY discoverableChanged) 0044 Q_PROPERTY(quint32 discoverableTimeout READ discoverableTimeout WRITE setDiscoverableTimeout NOTIFY discoverableTimeoutChanged) 0045 Q_PROPERTY(bool pairable READ isPairable WRITE setPairable NOTIFY pairableChanged) 0046 Q_PROPERTY(quint32 pairableTimeout READ pairableTimeout WRITE setPairableTimeout NOTIFY pairableTimeoutChanged) 0047 Q_PROPERTY(bool discovering READ isDiscovering NOTIFY discoveringChanged) 0048 Q_PROPERTY(QStringList uuids READ uuids NOTIFY uuidsChanged) 0049 Q_PROPERTY(QString modalias READ modalias NOTIFY modaliasChanged) 0050 Q_PROPERTY(LEAdvertisingManagerPtr leAdvertisingManager READ leAdvertisingManager NOTIFY leAdvertisingManagerChanged) 0051 Q_PROPERTY(MediaPtr media READ media NOTIFY mediaChanged) 0052 Q_PROPERTY(QList<DevicePtr> devices READ devices) 0053 0054 public: 0055 /** 0056 * Destroys an Adapter object. 0057 */ 0058 ~Adapter() override; 0059 0060 /** 0061 * Returns a shared pointer from this. 0062 * 0063 * @return AdapterPtr 0064 */ 0065 AdapterPtr toSharedPtr() const; 0066 0067 /** 0068 * Returns an UBI of the adapter. 0069 * 0070 * Example UBI: "/org/bluez/hci0" 0071 * 0072 * @return UBI of adapter 0073 */ 0074 QString ubi() const; 0075 0076 /** 0077 * Returns an address of the adapter. 0078 * 0079 * Example address: "1C:E5:C3:BC:94:7E" 0080 * 0081 * @return address of adapter 0082 */ 0083 QString address() const; 0084 0085 /** 0086 * Returns a name of the adapter. 0087 * 0088 * @return name of adapter 0089 */ 0090 QString name() const; 0091 0092 /** 0093 * Sets the name of the adapter. 0094 * 0095 * @param name name of adapter 0096 * @return void pending call 0097 */ 0098 PendingCall *setName(const QString &name); 0099 0100 /** 0101 * Returns a system name (hostname) of the adapter. 0102 * 0103 * @return system name of adapter 0104 */ 0105 QString systemName() const; 0106 0107 /** 0108 * Returns a class of the adapter. 0109 * 0110 * @return class of adapter 0111 */ 0112 quint32 adapterClass() const; 0113 0114 /** 0115 * Returns whether the adapter is powered on. 0116 * 0117 * @return true if adapter is powered on 0118 */ 0119 bool isPowered() const; 0120 0121 /** 0122 * Sets the powered state of the adapter. 0123 * 0124 * @param powered powered state 0125 * @return void pending call 0126 */ 0127 PendingCall *setPowered(bool powered); 0128 0129 /** 0130 * Returns whether the adapter is discoverable by other devices. 0131 * 0132 * @return true if adapter is discoverable 0133 */ 0134 bool isDiscoverable() const; 0135 0136 /** 0137 * Sets the discoverable state of the adapter. 0138 * 0139 * @param discoverable discoverable state 0140 * @return void pending call 0141 */ 0142 PendingCall *setDiscoverable(bool discoverable); 0143 0144 /** 0145 * Returns the discoverable timeout in seconds of the adapter. 0146 * 0147 * Discoverable timeout defines how long the adapter stays in 0148 * discoverable state after calling setDiscoverable(true). 0149 * 0150 * Timeout 0 means infinitely. 0151 * 0152 * @return discoverable timeout of adapter 0153 */ 0154 quint32 discoverableTimeout() const; 0155 0156 /** 0157 * Sets the discoverable timeout of the adapter. 0158 * 0159 * @param timeout timeout in seconds 0160 * @return void pending call 0161 */ 0162 PendingCall *setDiscoverableTimeout(quint32 timeout); 0163 0164 /** 0165 * Returns whether the adapter is pairable with other devices. 0166 * 0167 * @return true if adapter is pairable 0168 */ 0169 bool isPairable() const; 0170 0171 /** 0172 * Sets the pairable state of the adapter. 0173 * 0174 * @param pairable pairable state 0175 * @return void pending call 0176 */ 0177 PendingCall *setPairable(bool pairable); 0178 0179 /** 0180 * Returns the pairable timeout in seconds of the adapter. 0181 * 0182 * Pairable timeout defines how long the adapter stays in 0183 * pairable state after calling setPairable(true). 0184 * 0185 * Timeout 0 means infinitely. 0186 * 0187 * @return pairable timeout of adapter 0188 */ 0189 quint32 pairableTimeout() const; 0190 0191 /** 0192 * Sets the pairable timeout of the adapter. 0193 * 0194 * @param timeout timeout in seconds 0195 * @return void pending call 0196 */ 0197 PendingCall *setPairableTimeout(quint32 timeout); 0198 0199 /** 0200 * Returns whether the adapter is discovering for other devices 0201 * 0202 * @return true if adapter is discovering 0203 */ 0204 bool isDiscovering(); 0205 0206 /** 0207 * Returns UUIDs of supported services by the adapter. 0208 * 0209 * UUIDs will always be returned in uppercase. 0210 * 0211 * @return UUIDs of supported services 0212 */ 0213 QStringList uuids() const; 0214 0215 /** 0216 * Returns local device ID in modalias format. 0217 * 0218 * @return adapter modalias 0219 */ 0220 QString modalias() const; 0221 0222 /** 0223 * Returns the GATT manager interface for the adapter. 0224 * 0225 * @return null if adapter have no GATT manager 0226 */ 0227 GattManagerPtr gattManager() const; 0228 0229 /** 0230 * Returns the LE advertising manager interface for the adapter. 0231 * 0232 * @return null if adapter have no Bluetooth LE 0233 */ 0234 LEAdvertisingManagerPtr leAdvertisingManager() const; 0235 0236 /** 0237 * Returns the media interface for the adapter. 0238 * 0239 * @return null if adapter have no media 0240 */ 0241 MediaPtr media() const; 0242 0243 /** 0244 * Returns list of devices known by the adapter. 0245 * 0246 * @return list of devices 0247 */ 0248 QList<DevicePtr> devices() const; 0249 0250 /** 0251 * Returns a device for specified address. 0252 * 0253 * @param address address of device (eg. "40:79:6A:0C:39:75") 0254 * @return null if there is no device with specified address 0255 */ 0256 DevicePtr deviceForAddress(const QString &address) const; 0257 0258 /** 0259 * Starts device discovery. 0260 * 0261 * Possible errors: PendingCall::NotReady, PendingCall::Failed 0262 * 0263 * @return void pending call 0264 * @see discoverableTimeout() const 0265 */ 0266 PendingCall *startDiscovery(); 0267 0268 /** 0269 * Stops device discovery. 0270 * 0271 * Possible errors: PendingCall::NotReady, PendingCall::Failed, PendingCall::NotAuthorized 0272 * 0273 * @return void pending call 0274 */ 0275 PendingCall *stopDiscovery(); 0276 0277 /** 0278 * Removes the specified device. 0279 * 0280 * It will also remove the pairing information. 0281 * 0282 * Possible errors: PendingCall::InvalidArguments, PendingCall::Failed 0283 * 0284 * @param device device to be removed 0285 * @return void pending call 0286 */ 0287 PendingCall *removeDevice(DevicePtr device); 0288 0289 /** 0290 * Set the discovery filter for the caller. 0291 * 0292 * When this method is called with no filter parameter, the filter is removed. 0293 * 0294 * 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) 0295 * 0296 * Possible errors: PendingCall::InvalidArguments, PendingCall::Failed 0297 * 0298 * @param filter options dictionary 0299 * @return void pending call 0300 */ 0301 PendingCall *setDiscoveryFilter(const QVariantMap& filter); 0302 0303 /** 0304 * Get the discovery filters for the caller. 0305 * 0306 * 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) 0307 * 0308 * Possible errors: PendingCall::Failed 0309 * 0310 * @return string list pending call 0311 */ 0312 PendingCall *getDiscoveryFilters(); 0313 0314 Q_SIGNALS: 0315 /** 0316 * Indicates that the adapter was removed. 0317 */ 0318 void adapterRemoved(AdapterPtr adapter); 0319 0320 /** 0321 * Indicates that at least one of the adapter's properties have changed. 0322 */ 0323 void adapterChanged(AdapterPtr adapter); 0324 0325 /** 0326 * Indicates that adapter's name have changed. 0327 */ 0328 void nameChanged(const QString &name); 0329 0330 /** 0331 * Indicates that adapter's system name have changed. 0332 */ 0333 void systemNameChanged(const QString &systemName); 0334 0335 /** 0336 * Indicates that adapter's class have changed. 0337 */ 0338 void adapterClassChanged(quint32 adapterClass); 0339 0340 /** 0341 * Indicates that adapter's powered state have changed. 0342 */ 0343 void poweredChanged(bool powered); 0344 0345 /** 0346 * Indicates that adapter's discoverable state have changed. 0347 */ 0348 void discoverableChanged(bool discoverable); 0349 0350 /** 0351 * Indicates that adapter's discoverable timeout have changed. 0352 */ 0353 void discoverableTimeoutChanged(quint32 timeout); 0354 0355 /** 0356 * Indicates that adapter's pairable state have changed. 0357 */ 0358 void pairableChanged(bool pairable); 0359 0360 /** 0361 * Indicates that adapter's pairable timeout have changed. 0362 */ 0363 void pairableTimeoutChanged(quint32 timeout); 0364 0365 /** 0366 * Indicates that adapter's discovering state have changed. 0367 */ 0368 void discoveringChanged(bool discovering); 0369 0370 /** 0371 * Indicates that adapter's UUIDs have changed. 0372 */ 0373 void uuidsChanged(const QStringList &uuids); 0374 0375 /** 0376 * Indicates that adapter's modalias have changed. 0377 */ 0378 void modaliasChanged(const QString &modalias); 0379 0380 /** 0381 * Indicates that adapter's GATT manager have changed. 0382 */ 0383 void gattManagerChanged(GattManagerPtr gattManager); 0384 0385 /** 0386 * Indicates that adapter's LE advertising manager have changed. 0387 */ 0388 void leAdvertisingManagerChanged(LEAdvertisingManagerPtr leAdvertisingManager); 0389 0390 /** 0391 * Indicates that adapter's media have changed. 0392 */ 0393 void mediaChanged(MediaPtr media); 0394 0395 /** 0396 * Indicates that a new device was added (eg. found by discovery). 0397 */ 0398 void deviceAdded(DevicePtr device); 0399 0400 /** 0401 * Indicates that a device was removed. 0402 */ 0403 void deviceRemoved(DevicePtr device); 0404 0405 /** 0406 * Indicates that at least one of the device's properties have changed. 0407 */ 0408 void deviceChanged(DevicePtr device); 0409 0410 private: 0411 BLUEZQT_NO_EXPORT explicit Adapter(const QString &path, const QVariantMap &properties); 0412 0413 std::unique_ptr<class AdapterPrivate> const d; 0414 0415 friend class AdapterPrivate; 0416 friend class ManagerPrivate; 0417 friend class InitAdaptersJobPrivate; 0418 }; 0419 0420 } // namespace BluezQt 0421 0422 #endif // BLUEZQT_ADAPTER_H