4#include <QtCore/QLoggingCategory>
13Q_DECLARE_LOGGING_CATEGORY(QT_BT_BLUEZ)
15using namespace QtBluetoothPrivate;
18
19
20
21
23RemoteDeviceManager::RemoteDeviceManager(
24 const QBluetoothAddress &address, QObject *parent)
25 : QObject(parent), localAddress(address)
30 adapterPath = findAdapterForAddress(address, &ok);
31 if (!ok || adapterPath.isEmpty()) {
32 qCWarning(QT_BT_BLUEZ) <<
"Cannot initialize RemoteDeviceManager";
36bool RemoteDeviceManager::scheduleJob(JobType job,
const QList<QBluetoothAddress> &remoteDevices)
38 if (adapterPath.isEmpty())
41 for (
const auto& remote : remoteDevices)
42 jobQueue.push_back(std::make_pair(job, remote));
44 QTimer::singleShot(0,
this, [
this](){ runQueue(); });
48void RemoteDeviceManager::runQueue()
50 if (jobInProgress || adapterPath.isEmpty())
57 switch (jobQueue.front().first) {
58 case JobType::JobDisconnectDevice:
59 disconnectDevice(jobQueue.front().second);
66void RemoteDeviceManager::prepareNextJob()
68 Q_ASSERT(!jobQueue.empty());
71 jobInProgress =
false;
73 qCDebug(QT_BT_BLUEZ) <<
"RemoteDeviceManager job queue status:" << jobQueue.empty();
80void RemoteDeviceManager::disconnectDevice(
const QBluetoothAddress &remote)
83 OrgFreedesktopDBusObjectManagerInterface managerBluez5(
84 QStringLiteral(
"org.bluez"),
86 QDBusConnection::systemBus(),
this);
87 QDBusPendingReply<ManagedObjectList> reply = managerBluez5.GetManagedObjects();
88 reply.waitForFinished();
89 if (reply.isError()) {
90 QTimer::singleShot(0,
this, [
this](){ prepareNextJob(); });
94 bool jobStarted =
false;
96 for (
auto it = managedObjectList.constBegin(); it != managedObjectList.constEnd(); ++it) {
97 const QDBusObjectPath &path = it.key();
98 const InterfaceList &ifaceList = it.value();
100 for (
auto jt = ifaceList.constBegin(); jt != ifaceList.constEnd(); ++jt) {
101 const QString &iface = jt.key();
103 if (path.path().indexOf(adapterPath) != 0)
106 if (iface != QStringLiteral(
"org.bluez.Device1"))
109 const QBluetoothAddress foundAddress(ifaceList.value(iface).value(QStringLiteral(
"Address")).toString());
110 if (foundAddress != remote)
114 OrgBluezDevice1Interface* device1 =
new OrgBluezDevice1Interface(QStringLiteral(
"org.bluez"),
116 QDBusConnection::systemBus(),
118 QDBusPendingReply<> asyncReply = device1->Disconnect();
119 QDBusPendingCallWatcher* watcher =
new QDBusPendingCallWatcher(asyncReply,
this);
120 const auto watcherFinished = [
this, device1](QDBusPendingCallWatcher* call) {
122 device1->deleteLater();
125 connect(watcher, &QDBusPendingCallWatcher::finished,
this, watcherFinished);
132 qCDebug(QT_BT_BLUEZ) <<
"RemoteDeviceManager JobDisconnectDevice failed";
133 QTimer::singleShot(0,
this, [
this](){ prepareNextJob(); });
139#include "moc_remotedevicemanager_p.cpp"
QMap< QDBusObjectPath, InterfaceList > ManagedObjectList