File indexing completed on 2024-05-12 17:08:30
0001 /* 0002 * SPDX-FileCopyrightText: 2018-2019 Daniel Vrátil <dvratil@kde.org> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0005 */ 0006 0007 #ifndef FAKEMANAGER_H_ 0008 #define FAKEMANAGER_H_ 0009 0010 #include <QDBusObjectPath> 0011 #include <QJsonObject> 0012 #include <QList> 0013 #include <QObject> 0014 #include <QString> 0015 0016 #include <map> 0017 #include <memory> 0018 0019 class FakeManagerException : public std::runtime_error 0020 { 0021 public: 0022 FakeManagerException(const QString &what) 0023 : std::runtime_error(what.toStdString()) 0024 { 0025 } 0026 }; 0027 0028 class FakeDevice; 0029 class FakeManager : public QObject 0030 { 0031 Q_OBJECT 0032 Q_CLASSINFO("D-Bus Interface", "org.freedesktop.bolt1.Manager") 0033 0034 Q_PROPERTY(unsigned int Version READ version CONSTANT) 0035 Q_PROPERTY(bool Probing READ isProbing CONSTANT) 0036 Q_PROPERTY(QString DefaultPolicy READ defaultPolicy CONSTANT) 0037 Q_PROPERTY(QString SecurityLevel READ securityLevel CONSTANT) 0038 Q_PROPERTY(QString AuthMode READ authMode WRITE setAuthMode NOTIFY authModeChanged) 0039 0040 public: 0041 explicit FakeManager(const QJsonObject &json, QObject *parent = nullptr); 0042 explicit FakeManager(QObject *parent = nullptr); 0043 ~FakeManager() override; 0044 0045 unsigned int version() const; 0046 bool isProbing() const; 0047 QString defaultPolicy() const; 0048 QString securityLevel() const; 0049 QString authMode() const; 0050 void setAuthMode(const QString &authMode); 0051 0052 FakeDevice *addDevice(std::unique_ptr<FakeDevice> device); 0053 void removeDevice(const QString &uid); 0054 QList<FakeDevice *> devices() const; 0055 0056 Q_INVOKABLE QList<QDBusObjectPath> ListDevices() const; 0057 Q_INVOKABLE QDBusObjectPath DeviceByUid(const QString &uid) const; 0058 Q_INVOKABLE QDBusObjectPath EnrollDevice(const QString &uid, const QString &policy, const QString &flags); 0059 Q_INVOKABLE void ForgetDevice(const QString &uid); 0060 0061 Q_SIGNALS: 0062 void DeviceAdded(const QDBusObjectPath &device); 0063 void DeviceRemoved(const QDBusObjectPath &device); 0064 void authModeChanged(const QString &authMode); 0065 0066 private: 0067 bool mProbing = false; 0068 QString mDefaultPolicy = QStringLiteral("auto"); 0069 QString mSecurityLevel = QStringLiteral("none"); 0070 QString mAuthMode = QStringLiteral("enabled"); 0071 0072 std::map<QString /*uid*/, std::unique_ptr<FakeDevice>> mDevices; 0073 }; 0074 0075 #endif