4#include <QtCore/QGlobalStatic>
5#include <QtCore/QLoggingCategory>
7#include <QtCore/QVersionNumber>
8#include <QtNetwork/private/qnet_unix_p.h>
45 qDBusRegisterMetaType<InterfaceList>();
46 qDBusRegisterMetaType<ManagedObjectList>();
47 qDBusRegisterMetaType<ManufacturerDataList>();
48 qDBusRegisterMetaType<ServiceDataList>();
51 reply.waitForFinished();
52 if (
reply.isError()) {
54 qWarning() <<
"Cannot find a compatible running Bluez. "
55 "Please check the Bluez installation. "
56 "QtBluetooth requires at least BlueZ version 5.";
59 qCDebug(QT_BT_BLUEZ) <<
"Bluez 5 detected.";
90 if (!devRequestList) {
96 memset(pDevList.
data(), 0, devListSize);
98 devRequest = pDevList->dev_req;
106 if (devRequestList->
dev_num > 0) {
116 const int maxNoOfConnections = 20;
127 pInfoList->conn_num = maxNoOfConnections;
128 pInfoList->dev_id = devInfo.
dev_id;
157 if (bluezDaemonVersion()->isNull()) {
161 qDBusRegisterMetaType<InterfaceList>();
162 qDBusRegisterMetaType<ManagedObjectList>();
163 qDBusRegisterMetaType<ManufacturerDataList>();
164 qDBusRegisterMetaType<ServiceDataList>();
166 qCDebug(QT_BT_BLUEZ) <<
"Detecting bluetoothd version";
174 *bluezDaemonVersion() = vn;
175 qCDebug(QT_BT_BLUEZ) <<
"Forcing Bluez LE API selection:"
176 << bluezDaemonVersion()->toString();
189 process.waitForFinished();
194 qCDebug(QT_BT_BLUEZ) <<
"Detected bluetoothd version" << vn;
199 qCDebug(QT_BT_BLUEZ) <<
"Using /proc/<pid>/exe";
203 *bluezDaemonVersion() = vn;
205 if (bluezDaemonVersion()->isNull()) {
206 qCDebug(QT_BT_BLUEZ) <<
"Using /proc/<pid>/cmdline";
217 *bluezDaemonVersion() = determineBinaryVersion(
binary);
219 qCDebug(QT_BT_BLUEZ) <<
"Cannot determine bluetoothd version via cmdline:"
226 if (bluezDaemonVersion()->isNull()) {
235 if (bluezDaemonVersion()->isNull()) {
239 qCWarning(QT_BT_BLUEZ) <<
"Cannot determine bluetoothd version and required Bluetooth HCI ioctols";
240 qCWarning(QT_BT_BLUEZ) <<
"Disabling Qt Bluetooth LE feature";
243 qCDebug(QT_BT_BLUEZ) <<
"Bluetoothd:" << bluezDaemonVersion()->toString();
246 Q_ASSERT(!bluezDaemonVersion()->isNull());
247 return *bluezDaemonVersion();
288 qCDebug(QT_BT_BLUEZ) <<
"Creating QtBluezDiscoveryManager";
300 qCDebug(QT_BT_BLUEZ) <<
"Destroying QtBluezDiscoveryManager";
303 for (
const QString &adapterPath : adapterPaths) {
308 if (!
data->wasListeningAlready) {
311 iface.StopDiscovery();
322 return discoveryManager();
341 this, &QtBluezDiscoveryManager::PropertiesChanged);
342 data->propteryListener = propIface;
346 data->wasListeningAlready = iface.discovering();
350 if (!
data->wasListeningAlready)
351 iface.StartDiscovery();
364 if (
data->reference > 0)
368 if (!
data->wasListeningAlready) {
371 iface.StopDiscovery();
374 delete data->propteryListener;
392void QtBluezDiscoveryManager::InterfacesRemoved(
const QDBusObjectPath &object_path,
399 removeAdapterFromMonitoring(object_path.
path());
410 qobject_cast<OrgFreedesktopDBusPropertiesInterface *>(
sender());
419 if (!isDiscovering) {
430 removeAdapterFromMonitoring(propIface->
path());
434 iface.StartDiscovery();
440void QtBluezDiscoveryManager::removeAdapterFromMonitoring(
const QString &dbusPath)
466 reply.waitForFinished();
467 if (
reply.isError()) {
483 const QString &iface = jt.key();
486 AddressForPathType pair;
487 pair.first =
path.path();
490 if (!pair.second.isNull())
491 localAdapters.
append(pair);
503 if (wantedAddress.isNull())
504 return localAdapters.
front().first;
506 for (
const AddressForPathType &pair : std::as_const(localAdapters)) {
507 if (pair.second == wantedAddress)
535 reply.waitForFinished();
541 const bool peripheralSupported =
reply.value()
543 .contains(
"org.bluez.LEAdvertisingManager1"_L1);
545 qCDebug(QT_BT_BLUEZ) <<
"Peripheral role"
546 << (peripheralSupported ?
"" :
"not")
547 <<
"supported on" << hostAdapterPath;
548 return peripheralSupported ? hostAdapterPath :
QString{};
561 bool valid = (us >=
'a' && us <=
'z')
562 || (us >=
'A' && us <=
'Z')
563 || (us >=
'0' && us <=
'9')
575#include "moc_bluez5_helper_p.cpp"
QT_BEGIN_NAMESPACE enum Bluez5TestResultType Bluez5TestResult
QString adapterWithDBusPeripheralInterface(const QBluetoothAddress &localAddress)
QString sanitizeNameForDBus(const QString &text)
QString findAdapterForAddress(const QBluetoothAddress &wantedAddress, bool *ok=nullptr)
bool mandatoryHciIoctlsAvailable()
QVersionNumber bluetoothdVersion()
QT_BEGIN_NAMESPACE void initializeBluez5()
void PropertiesChanged(const QString &interface, const QVariantMap &changed_properties, const QStringList &invalidated_properties, const QDBusMessage &msg)
QString path() const
Returns the object path that this interface is associated with.
QDBusReply< uint > servicePid(const QString &serviceName) const
Returns the Unix Process ID (PID) for the process currently holding the bus service serviceName.
static QDBusConnection systemBus()
Returns a QDBusConnection object opened with the system bus.
QDBusConnectionInterface * interface() const
Returns a QDBusConnectionInterface object that represents the D-Bus server interface on this connecti...
QString path() const
Returns this object path.
void close() override
Calls QFileDevice::flush() and closes the file.
\inmodule QtCore \reentrant
bool isExecutable() const
Returns true if the file is executable; otherwise returns false.
bool open(OpenMode flags) override
Opens the file using OpenMode mode, returning true if successful; otherwise false.
QByteArray readAll()
Reads all remaining data from the device, and returns it as a byte array.
bool isEmpty() const noexcept
void append(parameter_type t)
T value(const Key &key, const T &defaultValue=T()) const
bool contains(const Key &key) const
size_type remove(const Key &key)
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
QObject * sender() const
Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; othe...
T * data() const noexcept
Returns the value of the pointer referenced by this object.
\macro QT_RESTRICTED_CAST_FROM_ASCII
static QString fromLocal8Bit(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool isNull() const
Returns true if this string is null; otherwise returns false.
qsizetype size() const
Returns the number of characters in this string.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
const QChar * unicode() const
Returns a Unicode representation of the string.
bool toBool() const
Returns the variant as a bool if the variant has userType() Bool.
bool isNull() const noexcept
Returns true if there are zero numerical segments, otherwise returns false.
static Q_CORE_EXPORT QVersionNumber fromString(QAnyStringView string, qsizetype *suffixIndex=nullptr)
QMap< QString, AdapterData * > references
OrgFreedesktopDBusObjectManagerInterface * manager
~QtBluezDiscoveryManager()
void discoveryInterrupted(const QString &adapterPath)
static QtBluezDiscoveryManager * instance()
bool registerDiscoveryInterest(const QString &adapterPath)
void unregisterDiscoveryInterest(const QString &adapterPath)
QSet< QString >::iterator it
Combined button and popup list for selecting options.
constexpr QBindableInterface iface
std::pair< T1, T2 > QPair
bool qt_haveLinuxProcfs()
static int qt_safe_close(int fd)
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 Q_GLOBAL_STATIC_WITH_ARGS(TYPE, NAME, ARGS)
#define Q_GLOBAL_STATIC(TYPE, NAME,...)
Q_DECL_COLD_FUNCTION Q_CORE_EXPORT QString qt_error_string(int errorCode=-1)
#define qCWarning(category,...)
#define qCDebug(category,...)
#define Q_DECLARE_LOGGING_CATEGORY(name)
static int qt_safe_ioctl(int sockfd, unsigned long request, T arg)
static int qt_safe_socket(int domain, int type, int protocol, int flags=0)
GLsizei GLsizei GLenum void * binary
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLsizei const GLchar *const * path
#define QStringLiteral(str)
QString qEnvironmentVariable(const char *varName, const QString &defaultValue)
QFileInfo info(fileName)
[8]
connect(quitButton, &QPushButton::clicked, &app, &QCoreApplication::quit, Qt::QueuedConnection)
QNetworkAccessManager manager
char * toString(const MyType &t)
[31]
OrgFreedesktopDBusPropertiesInterface * propteryListener
\inmodule QtCore \reentrant
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent