| 1 | /* |
| 2 | SPDX-FileCopyrightText: 2010 Michael Zanetti <mzanetti@kde.org> |
| 3 | SPDX-FileCopyrightText: 2010-2012 Lukáš Tinkl <ltinkl@redhat.com> |
| 4 | |
| 5 | SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL |
| 6 | */ |
| 7 | |
| 8 | #ifndef UDISKSMANAGER_H |
| 9 | #define UDISKSMANAGER_H |
| 10 | |
| 11 | #include "dbus/manager.h" |
| 12 | #include "udisks2.h" |
| 13 | #include "udisksdevice.h" |
| 14 | |
| 15 | #include <solid/devices/ifaces/devicemanager.h> |
| 16 | |
| 17 | #include <QSet> |
| 18 | |
| 19 | using PropertyMap = QMap<QString, QVariantMap>; |
| 20 | |
| 21 | namespace Solid |
| 22 | { |
| 23 | namespace Backends |
| 24 | { |
| 25 | namespace UDisks2 |
| 26 | { |
| 27 | class Manager : public Solid::Ifaces::DeviceManager |
| 28 | { |
| 29 | Q_OBJECT |
| 30 | |
| 31 | public: |
| 32 | enum FetchMode { |
| 33 | FetchIfNeeded, |
| 34 | CachedOnly, |
| 35 | }; |
| 36 | |
| 37 | Manager(QObject *parent); |
| 38 | std::unique_ptr<QObject> createDevice(const QString &udi) override; |
| 39 | QStringList devicesFromQuery(const QString &parentUdi, Solid::DeviceInterface::Type type) override; |
| 40 | QStringList allDevices() override; |
| 41 | QSet<Solid::DeviceInterface::Type> supportedInterfaces() const override; |
| 42 | QString udiPrefix() const override; |
| 43 | ~Manager() override; |
| 44 | |
| 45 | bool hasInterface(const QString &udi, const QString &interface); |
| 46 | QMap<QString, PropertyMap> allProperties(); |
| 47 | PropertyMap deviceProperties(const QString &udi); |
| 48 | QVariant deviceProperty(const QString &udi, const QString &name, FetchMode fetchMode = FetchIfNeeded); |
| 49 | |
| 50 | Q_SIGNALS: |
| 51 | void propertyChanged(const QString &udi, const QMap<QString, int> &changes); |
| 52 | |
| 53 | private Q_SLOTS: |
| 54 | void slotInterfacesAdded(const QDBusObjectPath &object_path, const VariantMapMap &interfaces_and_properties); |
| 55 | void slotInterfacesRemoved(const QDBusObjectPath &object_path, const QStringList &interfaces); |
| 56 | void slotPropertiesChanged(const QDBusMessage &msg); |
| 57 | |
| 58 | private: |
| 59 | QMap<QString, PropertyMap> deviceCache(); |
| 60 | void updateBackend(const QString &udi); |
| 61 | QSet<Solid::DeviceInterface::Type> m_supportedInterfaces; |
| 62 | org::freedesktop::DBus::ObjectManager m_manager; |
| 63 | |
| 64 | // Optical media can be removed from the list of "known" devices |
| 65 | // but we still want to cache their properties for when the media is inserted back. |
| 66 | QStringList m_devices; |
| 67 | QMap<QString, PropertyMap> m_cache; |
| 68 | }; |
| 69 | |
| 70 | } |
| 71 | } |
| 72 | } |
| 73 | #endif // UDISKSMANAGER_H |
| 74 | |