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> |
6 | #include "neard_helper_p.h" |
7 | #include "objectmanager_interface.h" |
8 | |
9 | QT_BEGIN_NAMESPACE |
10 | |
11 | Q_DECLARE_LOGGING_CATEGORY(QT_NFC_NEARD) |
12 | Q_GLOBAL_STATIC(NeardHelper, neardHelper) |
13 | |
14 | NeardHelper::NeardHelper(QObject *parent) : |
15 | QObject(parent) |
16 | { |
17 | qDBusRegisterMetaType<InterfaceList>(); |
18 | qDBusRegisterMetaType<ManagedObjectList>(); |
19 | |
20 | m_dbusObjectManager = new OrgFreedesktopDBusObjectManagerInterface(QStringLiteral("org.neard"), |
21 | QStringLiteral("/"), |
22 | QDBusConnection::systemBus(), |
23 | this); |
24 | if (!m_dbusObjectManager->isValid()) { |
25 | qCCritical(QT_NFC_NEARD) << "dbus object manager invalid"; |
26 | return; |
27 | } |
28 | |
29 | connect(m_dbusObjectManager, &OrgFreedesktopDBusObjectManagerInterface::InterfacesAdded, |
30 | this, &NeardHelper::interfacesAdded); |
31 | connect(m_dbusObjectManager, &OrgFreedesktopDBusObjectManagerInterface::InterfacesRemoved, |
32 | this, &NeardHelper::interfacesRemoved); |
33 | } |
34 | |
35 | NeardHelper *NeardHelper::instance() |
36 | { |
37 | return neardHelper(); |
38 | } |
39 | |
40 | OrgFreedesktopDBusObjectManagerInterface *NeardHelper::dbusObjectManager() |
41 | { |
42 | return m_dbusObjectManager; |
43 | } |
44 | |
45 | void NeardHelper::interfacesAdded(const QDBusObjectPath &path, InterfaceList interfaceList) |
46 | { |
47 | const QList<QString> keys = interfaceList.keys(); |
48 | for (const QString &key : keys) { |
49 | if (key == QStringLiteral("org.neard.Tag")) { |
50 | emit tagFound(path); |
51 | break; |
52 | } |
53 | if (key == QStringLiteral("org.neard.Record")) { |
54 | emit recordFound(path); |
55 | break; |
56 | } |
57 | } |
58 | } |
59 | |
60 | void NeardHelper::interfacesRemoved(const QDBusObjectPath &path, const QStringList &list) |
61 | { |
62 | if (list.contains(QStringLiteral("org.neard.Record"))) { |
63 | qCDebug(QT_NFC_NEARD) << "record removed"<< path.path(); |
64 | emit recordRemoved(path); |
65 | } else if (list.contains(QStringLiteral("org.neard.Tag"))) { |
66 | qCDebug(QT_NFC_NEARD) << "tag removed"<< path.path(); |
67 | emit tagRemoved(path); |
68 | } |
69 | } |
70 | |
71 | QT_END_NAMESPACE |
72 |