File indexing completed on 2024-10-06 05:01:00
0001 // SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0002 // SPDX-FileCopyrightText: 2020 Harald Sitter <sitter@kde.org> 0003 0004 #pragma once 0005 0006 #include <QChildEvent> 0007 #include <QDBusObjectPath> 0008 #include <QDebug> 0009 #include <QMetaObject> 0010 #include <QMetaProperty> 0011 0012 // Be very mindful when changing anything here. QMetaType<->DBus is very finicky. 0013 typedef QMap<QString, QVariant> KDBusObjectManagerPropertiesMap; 0014 typedef QMap<QString, KDBusObjectManagerPropertiesMap> KDBusObjectManagerInterfacePropertiesMap; 0015 typedef QMap<QDBusObjectPath, KDBusObjectManagerInterfacePropertiesMap> KDBusObjectManagerObjectPathInterfacePropertiesMap; 0016 typedef QStringList KDBusObjectManagerInterfaceList; 0017 0018 Q_DECLARE_METATYPE(KDBusObjectManagerPropertiesMap); 0019 Q_DECLARE_METATYPE(KDBusObjectManagerInterfacePropertiesMap); 0020 Q_DECLARE_METATYPE(KDBusObjectManagerObjectPathInterfacePropertiesMap); 0021 Q_DECLARE_METATYPE(KDBusObjectManagerInterfaceList); 0022 0023 class KDBusObjectManagerServer : public QObject 0024 { 0025 Q_OBJECT 0026 Q_CLASSINFO("D-Bus Interface", "org.freedesktop.DBus.ObjectManager") 0027 typedef QHash<QString, const QMetaObject *> InterfaceMetaObjectHash; 0028 0029 public: 0030 KDBusObjectManagerServer(QObject *parent = nullptr); 0031 bool serve(QObject *object); 0032 void unserve(QObject *object); 0033 0034 static void registerTypes(); 0035 0036 public Q_SLOTS: 0037 KDBusObjectManagerObjectPathInterfacePropertiesMap GetManagedObjects(); 0038 0039 Q_SIGNALS: 0040 void InterfacesAdded(QDBusObjectPath path, KDBusObjectManagerInterfacePropertiesMap map); 0041 void InterfacesRemoved(QDBusObjectPath path, KDBusObjectManagerInterfaceList list); 0042 0043 protected: 0044 QDBusObjectPath path(const QObject *object); 0045 KDBusObjectManagerInterfacePropertiesMap interfacePropertiesMap(const QObject *child); 0046 0047 private: 0048 InterfaceMetaObjectHash metaObjectsFor(const QObject *object); 0049 0050 const QString m_path = QStringLiteral("/modules/smart/devices"); 0051 QList<QObject *> m_managedObjects; 0052 };