4#include <QtCore/QLoggingCategory>
6#include <QtCore/qcoreapplication.h>
26 adapterAddress(deviceAdapter),
38 this->_q_InterfacesAdded(objectPath, interfacesAndProperties);
74 if (pendingCancel ==
true) {
81 discoveredDevices.
clear();
82 devicesProperties.clear();
89 qCWarning(QT_BT_BLUEZ) <<
"Cannot find Bluez 5 adapter for device search" <<
ok;
91 errorString = QBluetoothDeviceDiscoveryAgent::tr(
"Cannot find valid Bluetooth adapter.");
92 q->errorOccurred(lastError);
99 if (!adapter->powered()) {
100 qCDebug(QT_BT_BLUEZ) <<
"Aborting device discovery due to offline Bluetooth Adapter";
102 errorString = QBluetoothDeviceDiscoveryAgent::tr(
"Device is powered off");
105 emit q->errorOccurred(lastError);
124 qCDebug(QT_BT_BLUEZ) <<
"Discovery method" <<
methods <<
"not supported";
126 errorString = QBluetoothDeviceDiscoveryAgent::tr(
"One or more device discovery methods "
127 "are not supported on this platform");
130 emit q->errorOccurred(lastError);
133 qCDebug(QT_BT_BLUEZ) <<
"SetDiscoveryFilter failed:" << filterReply.
error();
140 this->_q_discoveryInterrupted(
path);
148 this->_q_PropertiesChanged(
interface,
signal.path(), changedProperties, invalidatedProperties);
152 propertyMonitors.append(prop);
156 reply.waitForFinished();
157 if (!
reply.isError()) {
168 if (
path.path().indexOf(adapter->path()) != 0)
171 deviceFound(
path.path(), jt.value());
180 if (!discoveryTimer) {
181 discoveryTimer =
new QTimer(
q);
182 discoveryTimer->setSingleShot(
true);
185 this->_q_discoveryFinished();
189 if (lowEnergySearchTimeout > 0) {
190 discoveryTimer->setInterval(lowEnergySearchTimeout);
191 discoveryTimer->start();
201 pendingCancel =
true;
202 pendingStart =
false;
203 _q_discoveryFinished();
210 if (btAddress.isNull())
220 bool foundLikelyLowEnergyUuid =
false;
222 for (
const auto &u: foundUuids) {
227 if (!foundLikelyLowEnergyUuid) {
232 if (
ok && ((shortId & genericAccessInt) == genericAccessInt))
233 foundLikelyLowEnergyUuid =
true;
243 if (foundLikelyLowEnergyUuid)
251 key, deviceManufacturerData.
value(
key).variant().toByteArray());
258 deviceServiceData.
value(
key).variant().toByteArray());
263void QBluetoothDeviceDiscoveryAgentPrivate::deviceFound(
const QString &devicePath,
272 if (deviceAdapter.path() != adapter->path())
282 <<
"total device" << discoveredDevices.
size() <<
"cached"
283 <<
"RSSI" << deviceInfo.
rssi()
292 if (lowEnergySearchTimeout > 0 && discoveredDevices[
i] == deviceInfo) {
296 discoveredDevices.
replace(
i, deviceInfo);
298 emit q->deviceDiscovered(deviceInfo);
303 discoveredDevices.
append(deviceInfo);
304 emit q->deviceDiscovered(deviceInfo);
307void QBluetoothDeviceDiscoveryAgentPrivate::_q_InterfacesAdded(
const QDBusObjectPath &object_path,
318 deviceFound(object_path.
path(),
323void QBluetoothDeviceDiscoveryAgentPrivate::_q_discoveryFinished()
328 discoveryTimer->stop();
334 propertyMonitors.clear();
339 if (pendingCancel && !pendingStart) {
340 pendingCancel =
false;
342 }
else if (pendingStart) {
343 pendingStart =
false;
344 pendingCancel =
false;
352void QBluetoothDeviceDiscoveryAgentPrivate::_q_discoveryInterrupted(
const QString &
path)
359 if (
path == adapter->path()) {
360 qCWarning(QT_BT_BLUEZ) <<
"Device discovery aborted due to unexpected adapter changes from another process.";
363 discoveryTimer->stop();
372 errorString = QBluetoothDeviceDiscoveryAgent::tr(
"Bluetooth adapter error");
374 emit q->errorOccurred(lastError);
378void QBluetoothDeviceDiscoveryAgentPrivate::_q_PropertiesChanged(
const QString &
interface,
387 if (!devicesProperties.contains(
path))
393 for (QVariantMap::const_iterator
it = changed_properties.
constBegin();
412 qCDebug(QT_BT_BLUEZ) <<
"Updating RSSI for" <<
info.address()
414 discoveredDevices[
i].setRssi(
419 qCDebug(QT_BT_BLUEZ) <<
"Updating ManufacturerData for" <<
info.address();
421 qdbus_cast< ManufacturerDataList >(changed_properties.
value(
QStringLiteral(
"ManufacturerData")));
424 bool wasNewValue =
false;
426 bool added = discoveredDevices[
i].setManufacturerData(
key, changedManufacturerData.
value(
key).variant().toByteArray());
427 wasNewValue = (wasNewValue || added);
434 if (lowEnergySearchTimeout > 0) {
435 if (discoveredDevices[
i] !=
info) {
436 if (discoveredDevices.
at(
i).
name() ==
info.name()) {
437 qCDebug(QT_BT_BLUEZ) <<
"Almost Duplicate " <<
info.address()
438 <<
info.name() <<
"- replacing in place";
444 emit q->deviceUpdated(discoveredDevices[
i], updatedFields);
454 emit q->deviceUpdated(discoveredDevices[
i], updatedFields);
static JNINativeMethod methods[]
QString findAdapterForAddress(const QBluetoothAddress &wantedAddress, bool *ok=nullptr)
QT_BEGIN_NAMESPACE void initializeBluez5()
static BluetoothManagement * instance()
void InterfacesAdded(const QDBusObjectPath &object_path, InterfaceList interfaces_and_properties)
void PropertiesChanged(const QString &interface, const QVariantMap &changed_properties, const QStringList &invalidated_properties, const QDBusMessage &msg)
~QBluetoothDeviceDiscoveryAgentPrivate()
void start(QBluetoothDeviceDiscoveryAgent::DiscoveryMethods methods)
QBluetoothDeviceDiscoveryAgentPrivate(const QBluetoothAddress &deviceAdapter, QBluetoothDeviceDiscoveryAgent *parent)
static DiscoveryMethods supportedDiscoveryMethods()
This function returns the discovery methods supported by the current platform.
void deviceDiscovered(const QBluetoothDeviceInfo &info)
This signal is emitted when the Bluetooth device described by info is discovered.
@ UnsupportedDiscoveryMethod
@ BaseRateAndLowEnergyCoreConfiguration
@ LowEnergyCoreConfiguration
@ BaseRateCoreConfiguration
QBluetoothAddress address() const
Returns the address of the device.
QByteArray manufacturerData(quint16 manufacturerId) const
Returns the data associated with the given manufacturerId.
bool isValid() const
Returns true if the QBluetoothDeviceInfo object is valid, otherwise returns false.
void setServiceUuids(const QList< QBluetoothUuid > &uuids)
Sets the list of service UUIDs to uuids.
void setRssi(qint16 signal)
Set the signal strength value, used internally.
QByteArray serviceData(const QBluetoothUuid &serviceId) const
Returns the data associated with the given serviceId.
QList< QBluetoothUuid > serviceUuids() const
Returns the list of service UUIDs supported by the device.
bool setServiceData(const QBluetoothUuid &serviceId, const QByteArray &data)
Sets the advertised service data for the given serviceId.
QString name() const
Returns the name assigned to the device.
qint16 rssi() const
Returns the signal strength when the device was last scanned.
bool setManufacturerData(quint16 manufacturerId, const QByteArray &data)
Sets the advertised manufacturer data for the given manufacturerId.
void setCoreConfigurations(QBluetoothDeviceInfo::CoreConfigurations coreConfigs)
Sets the CoreConfigurations of the device to coreConfigs.
qsizetype size() const noexcept
Returns the number of bytes in this byte array.
static QDBusConnection systemBus()
Returns a QDBusConnection object opened with the system bus.
ErrorType type() const
Returns this error's ErrorType.
QString name() const
Returns this error's name.
QString path() const
Returns this object path.
qsizetype size() const noexcept
const_reference at(qsizetype i) const noexcept
void replace(qsizetype i, parameter_type t)
void append(parameter_type t)
iterator insert(const Key &key, const T &value)
T value(const Key &key, const T &defaultValue=T()) const
bool contains(const Key &key) const
QList< Key > keys() const
const_iterator constBegin() const
const_iterator constEnd() const
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
\threadsafe
\macro QT_RESTRICTED_CAST_FROM_ASCII
void clear()
Clears the contents of the string and makes it null.
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.
void discoveryInterrupted(const QString &adapterPath)
static QtBluezDiscoveryManager * instance()
bool registerDiscoveryInterest(const QString &adapterPath)
void unregisterDiscoveryInterest(const QString &adapterPath)
QMap< QString, QString > map
[6]
qDeleteAll(list.begin(), list.end())
QSet< QString >::iterator it
Combined button and popup list for selecting options.
constexpr QBindableInterface iface
static QBluetoothDeviceInfo createDeviceInfoFromBluez5Device(const QVariantMap &properties)
static const QCssKnownValue properties[NumProperties - 1]
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)
GLuint GLuint64EXT address
GLdouble GLdouble GLdouble GLdouble q
GLsizei const GLchar *const * path
#define QStringLiteral(str)
static int toInt(const QChar &qc, int R)
QFileInfo info(fileName)
[8]
settings remove("monkey")
QNetworkAccessManager manager
char * toString(const MyType &t)
[31]
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent