File indexing completed on 2024-07-14 03:50:58

0001 /*
0002  * SPDX-FileCopyrightText: 2014-2015 David Rosca <nowrep@gmail.com>
0003  *
0004  * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005  */
0006 
0007 #ifndef OBJECTMANAGER_H
0008 #define OBJECTMANAGER_H
0009 
0010 #include <QDBusAbstractAdaptor>
0011 #include <QDBusObjectPath>
0012 #include <QVariantMap>
0013 
0014 typedef QMap<QString, QVariantMap> QVariantMapMap;
0015 Q_DECLARE_METATYPE(QVariantMapMap)
0016 
0017 typedef QMap<QDBusObjectPath, QVariantMapMap> DBusManagerStruct;
0018 Q_DECLARE_METATYPE(DBusManagerStruct)
0019 
0020 class Object;
0021 
0022 class ObjectManager : public QDBusAbstractAdaptor
0023 {
0024     Q_OBJECT
0025     Q_CLASSINFO("D-Bus Interface", "org.freedesktop.DBus.ObjectManager")
0026 
0027 public:
0028     explicit ObjectManager(QObject *parent = nullptr);
0029     ~ObjectManager() override;
0030 
0031     void addObject(Object *object);
0032     void removeObject(Object *object);
0033 
0034     void addAutoDeleteObject(QObject *object);
0035 
0036     Object *objectByPath(const QDBusObjectPath &path) const;
0037 
0038     static ObjectManager *self();
0039 
0040 public Q_SLOTS:
0041     DBusManagerStruct GetManagedObjects();
0042 
0043 Q_SIGNALS:
0044     void InterfacesAdded(const QDBusObjectPath &object, const QVariantMapMap &interfaces);
0045     void InterfacesRemoved(const QDBusObjectPath &object, const QStringList &interfaces);
0046 
0047 private:
0048     QMultiMap<QString, Object *> m_objects;
0049     QList<QObject *> m_autoDeleteObjects;
0050 };
0051 
0052 #endif // OBJECTMANAGER_H