4#include <QtCore/QLoggingCategory>
5#include <QtCore/QRandomGenerator>
6#include <QtDBus/QDBusContext>
26 d_ptr->currentMode = hostMode();
33 d_ptr->currentMode = hostMode();
39 return d_ptr->adapter->alias();
55 d_ptr->adapter->setPowered(
true);
65 if (
d->pendingHostModeChange != -1) {
66 qCWarning(QT_BT_BLUEZ) <<
"setHostMode() ignored due to already pending mode change";
77 d->adapter->setPowered(
true);
79 d->adapter->setDiscoverable(
true);
85 d->adapter->setPowered(
true);
87 d->adapter->setDiscoverable(
false);
91 d->adapter->setPowered(
false);
99 if (!d_ptr->adapter->powered())
101 else if (d_ptr->adapter->discoverable())
103 else if (d_ptr->adapter->powered())
112 return d_ptr->connectedDevices();
123 reply.waitForFinished();
142 if (hostInfo.
address().isNull())
145 localDevices.
append(hostInfo);
162 if (current_pairing == pairing) {
163 if (d_ptr->adapter) {
165 if (d_ptr->pairingDiscoveryTimer && d_ptr->pairingDiscoveryTimer->isActive()) {
166 d_ptr->pairingDiscoveryTimer->stop();
169 if (d_ptr->pairingTarget) {
170 qCDebug(QT_BT_BLUEZ) <<
"Cancelling pending pairing request to" << d_ptr->pairingTarget->address();
173 delete d_ptr->pairingTarget;
174 d_ptr->pairingTarget =
nullptr;
193 if (pairingDiscoveryTimer && pairingDiscoveryTimer->isActive()) {
194 pairingDiscoveryTimer->stop();
199 delete pairingTarget;
200 pairingTarget =
nullptr;
208 reply.waitForFinished();
209 if (
reply.isError()) {
220 const QString &iface = jt.key();
228 qCDebug(QT_BT_BLUEZ) <<
"Initiating direct pair to" << targetAddress.toString();
230 processPairing(
path.path(), targetPairing);
241 pairing = targetPairing;
242 if (!pairingDiscoveryTimer) {
243 pairingDiscoveryTimer =
new QTimer(
this);
244 pairingDiscoveryTimer->setSingleShot(
true);
245 pairingDiscoveryTimer->setInterval(20000);
247 this, &QBluetoothLocalDevicePrivate::pairingDiscoveryTimedOut);
250 qCDebug(QT_BT_BLUEZ) <<
"Initiating discovery for pairing on" << targetAddress.toString();
251 pairingDiscoveryTimer->start();
261void QBluetoothLocalDevicePrivate::processPairing(
const QString &objectPath,
265 delete pairingTarget;
268 if (pairingDiscoveryTimer && pairingDiscoveryTimer->isActive()) {
269 pairingDiscoveryTimer->stop();
282 delete pairingTarget;
283 pairingTarget =
nullptr;
303 if (!pairingTarget->paired()) {
304 qCDebug(QT_BT_BLUEZ) <<
"Sending pairing request to" << pairingTarget->address();
309 this, &QBluetoothLocalDevicePrivate::pairingCompleted);
315 pairingTarget->setTrusted(
true);
317 pairingTarget->setTrusted(
false);
319 delete pairingTarget;
320 pairingTarget =
nullptr;
330void QBluetoothLocalDevicePrivate::pairingDiscoveryTimedOut()
332 qCWarning(QT_BT_BLUEZ) <<
"Discovery for pairing purposes failed. Cannot find parable device.";
348 reply.waitForFinished();
385 pendingHostModeChange(-1),
392 connectDeviceChanges();
400void QBluetoothLocalDevicePrivate::connectDeviceChanges()
405 reply.waitForFinished();
429 this, &QBluetoothLocalDevicePrivate::PropertiesChanged);
430 deviceChangeMonitors.insert(
path.path(), monitor);
434 connectedDevicesSet.insert(
address);
445 delete adapterProperties;
447 delete pairingTarget;
452void QBluetoothLocalDevicePrivate::initializeAdapter()
465 this, &QBluetoothLocalDevicePrivate::InterfacesAdded);
467 this, &QBluetoothLocalDevicePrivate::InterfacesRemoved);
474 deviceAdapterPath = adapterPath;
484 this, &QBluetoothLocalDevicePrivate::PropertiesChanged);
488void QBluetoothLocalDevicePrivate::PropertiesChanged(
const QString &
interface,
501 if (!adapter->powered()) {
504 if (adapter->discoverable())
509 if (pendingHostModeChange != -1) {
511 if (
static_cast<int>(
mode) != pendingHostModeChange) {
512 adapter->setDiscoverable(
513 pendingHostModeChange
515 pendingHostModeChange = -1;
518 pendingHostModeChange = -1;
522 if (
mode != currentMode)
531 qobject_cast<OrgFreedesktopDBusPropertiesInterface*>(
sender());
540 bool isInSet = connectedDevicesSet.contains(changedAddress);
541 if (isConnected && !isInSet) {
542 connectedDevicesSet.insert(changedAddress);
544 }
else if (!isConnected && isInSet) {
545 connectedDevicesSet.remove(changedAddress);
554 && !deviceChangeMonitors.contains(object_path.
path())) {
563 this, &QBluetoothLocalDevicePrivate::PropertiesChanged);
564 deviceChangeMonitors.insert(object_path.
path(), monitor);
569 connectedDevicesSet.insert(
address);
575 if (pairingDiscoveryTimer && pairingDiscoveryTimer->isActive()
581 processPairing(object_path.
path(), pairing);
585void QBluetoothLocalDevicePrivate::InterfacesRemoved(
const QDBusObjectPath &object_path,
588 if (deviceChangeMonitors.contains(object_path.
path())
589 && interfaces.contains(
QLatin1String(
"org.bluez.Device1"))) {
593 delete deviceChangeMonitors.take(object_path.
path());
600 bool found = connectedDevicesSet.remove(
address);
606 if (adapter && object_path.
path() == adapter->path()
607 && interfaces.contains(
QLatin1String(
"org.bluez.Adapter1"))) {
608 qCDebug(QT_BT_BLUEZ) <<
"Adapter" << adapter->path() <<
"was removed";
614 delete adapterProperties;
615 adapterProperties =
nullptr;
617 delete pairingTarget;
618 pairingTarget =
nullptr;
622 deviceChangeMonitors.clear();
623 connectedDevicesSet.clear();
634 return connectedDevicesSet.values();
642 if (
reply.isError()) {
651 if (!pairingTarget) {
652 qCWarning(QT_BT_BLUEZ) <<
"Pairing target expected but found null pointer.";
658 if (!pairingTarget->paired()) {
659 qCWarning(QT_BT_BLUEZ) <<
"Device was not paired as requested";
668 pairingTarget->setTrusted(
true);
670 pairingTarget->setTrusted(
false);
672 delete pairingTarget;
673 pairingTarget =
nullptr;
675 emit q->pairingFinished(targetAddress, pairing);
683#include "moc_qbluetoothlocaldevice_p.cpp"
QString findAdapterForAddress(const QBluetoothAddress &wantedAddress, bool *ok=nullptr)
QT_BEGIN_NAMESPACE void initializeBluez5()
IOBluetoothDevice * device
void InterfacesAdded(const QDBusObjectPath &object_path, InterfaceList interfaces_and_properties)
void InterfacesRemoved(const QDBusObjectPath &object_path, const QStringList &interfaces)
void PropertiesChanged(const QString &interface, const QVariantMap &changed_properties, const QStringList &invalidated_properties, const QDBusMessage &msg)
QBluetoothAddress address() const
Returns the Bluetooth address as a QBluetoothAddress.
void setAddress(const QBluetoothAddress &address)
Sets the Bluetooth address for this Bluetooth host info object.
void setName(const QString &name)
Sets the name of the host info object.
QBluetoothLocalDevicePrivate(QBluetoothLocalDevice *, const QBluetoothAddress &=QBluetoothAddress())
~QBluetoothLocalDevicePrivate()
void requestPairing(const QBluetoothAddress &address, Pairing pairing)
void powerOn()
Powers on the device after returning it to the hostMode() state, if it was powered off.
Pairing
This enum describes the pairing state between the two Bluetooth devices.
void errorOccurred(QBluetoothLocalDevice::Error error)
Signal emitted if there's an exceptional error while pairing.
void requestPairing(const QBluetoothAddress &address, Pairing pairing)
Set the pairing status with address.
HostMode
This enum describes the most of the local Bluetooth device.
@ HostDiscoverableLimitedInquiry
HostMode hostMode() const
Returns the current host mode of this local Bluetooth device.
void deviceConnected(const QBluetoothAddress &address)
Error
This enum describes errors that maybe returned.
QList< QBluetoothAddress > connectedDevices() const
QBluetoothLocalDevice(QObject *parent=nullptr)
Constructs a QBluetoothLocalDevice with parent.
QString name() const
Returns the name assgined by the user to this Bluetooth device.
static QList< QBluetoothHostInfo > allDevices()
Returns a list of all available local Bluetooth devices.
Pairing pairingStatus(const QBluetoothAddress &address) const
Returns the current bluetooth pairing status of address, if it's unpaired, paired,...
QBluetoothAddress address() const
Returns the MAC address of this Bluetooth device.
void deviceDisconnected(const QBluetoothAddress &address)
void setHostMode(QBluetoothLocalDevice::HostMode mode)
Sets the host mode of this local Bluetooth device to mode.
void hostModeStateChanged(QBluetoothLocalDevice::HostMode state)
The state of the host has transitioned to a different HostMode.
QString path() const
Returns the object path that this interface is associated with.
static QDBusConnection systemBus()
Returns a QDBusConnection object opened with the system bus.
QString path() const
Returns this object path.
void finished(QDBusPendingCallWatcher *self=nullptr)
This signal is emitted when the pending call has finished and its reply is available.
void append(parameter_type t)
T value(const Key &key, const T &defaultValue=T()) const
bool contains(const Key &key) const
const_iterator constBegin() const
const_iterator constEnd() const
NetworkError error() const
Returns the error that was found during the processing of this request.
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
QObject * sender() const
Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; othe...
void deleteLater()
\threadsafe
\macro QT_RESTRICTED_CAST_FROM_ASCII
QString right(qsizetype n) const
Returns a substring that contains the n rightmost characters of the string.
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
QString & replace(qsizetype i, qsizetype len, QChar after)
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
void timeout(QPrivateSignal)
This signal is emitted when the timer times out.
QString toString() const
Returns the variant as a QString if the variant has a userType() including, but not limited to:
bool toBool() const
Returns the variant as a bool if the variant has userType() Bool.
static QtBluezDiscoveryManager * instance()
bool registerDiscoveryInterest(const QString &adapterPath)
void unregisterDiscoveryInterest(const QString &adapterPath)
qDeleteAll(list.begin(), list.end())
QSet< QString >::iterator it
Combined button and popup list for selecting options.
constexpr QBindableInterface iface
bool objectPathIsForThisDevice(const QString &adapterPath, const QString &objectPath)
QT_BEGIN_NAMESPACE void registerQBluetoothLocalDeviceMetaType()
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char * interface
#define qCWarning(category,...)
#define qCDebug(category,...)
#define Q_DECLARE_LOGGING_CATEGORY(name)
#define Q_ARG(Type, data)
GLuint GLuint64EXT address
GLdouble GLdouble GLdouble GLdouble q
GLsizei const GLchar *const * path
#define QStringLiteral(str)
QFutureWatcher< int > watcher
QNetworkAccessManager manager
char * toString(const MyType &t)
[31]
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent
QT_BEGIN_NAMESPACE bool toBool(const QString &str)