Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
neard_helper.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// Copyright (C) 2016 BasysKom GmbH.
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4
5#include <QDBusMetaType>
7#include "objectmanager_interface.h"
8
10
11Q_DECLARE_LOGGING_CATEGORY(QT_NFC_NEARD)
12Q_GLOBAL_STATIC(NeardHelper, neardHelper)
13
14using namespace QtNfcPrivate; // for D-Bus wrappers
15
16NeardHelper::NeardHelper(QObject *parent) :
17 QObject(parent)
18{
19 qDBusRegisterMetaType<InterfaceList>();
20 qDBusRegisterMetaType<ManagedObjectList>();
21
22 m_dbusObjectManager = new OrgFreedesktopDBusObjectManagerInterface(QStringLiteral("org.neard"),
23 QStringLiteral("/"),
24 QDBusConnection::systemBus(),
25 this);
26 if (!m_dbusObjectManager->isValid()) {
27 qCCritical(QT_NFC_NEARD) << "dbus object manager invalid";
28 return;
29 }
30
31 connect(m_dbusObjectManager, &OrgFreedesktopDBusObjectManagerInterface::InterfacesAdded,
32 this, &NeardHelper::interfacesAdded);
33 connect(m_dbusObjectManager, &OrgFreedesktopDBusObjectManagerInterface::InterfacesRemoved,
34 this, &NeardHelper::interfacesRemoved);
35}
36
37NeardHelper *NeardHelper::instance()
38{
39 return neardHelper();
40}
41
42OrgFreedesktopDBusObjectManagerInterface *NeardHelper::dbusObjectManager()
43{
44 return m_dbusObjectManager;
45}
46
47void NeardHelper::interfacesAdded(const QDBusObjectPath &path, InterfaceList interfaceList)
48{
49 const QList<QString> keys = interfaceList.keys();
50 for (const QString &key : keys) {
51 if (key == QStringLiteral("org.neard.Tag")) {
52 emit tagFound(path);
53 break;
54 }
55 if (key == QStringLiteral("org.neard.Record")) {
56 emit recordFound(path);
57 break;
58 }
59 }
60}
61
62void NeardHelper::interfacesRemoved(const QDBusObjectPath &path, const QStringList &list)
63{
64 if (list.contains(QStringLiteral("org.neard.Record"))) {
65 qCDebug(QT_NFC_NEARD) << "record removed" << path.path();
66 emit recordRemoved(path);
67 } else if (list.contains(QStringLiteral("org.neard.Tag"))) {
68 qCDebug(QT_NFC_NEARD) << "tag removed" << path.path();
69 emit tagRemoved(path);
70 }
71}
72
73QT_END_NAMESPACE
QMap< QDBusObjectPath, InterfaceList > ManagedObjectList