File indexing completed on 2024-05-12 05:36:53
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 MANAGER_H_ 0008 #define MANAGER_H_ 0009 0010 #include <QObject> 0011 #include <QSharedPointer> 0012 0013 #include <functional> 0014 #include <memory> 0015 0016 #include "enum.h" 0017 #include "kbolt_export.h" 0018 0019 class QDBusObjectPath; 0020 class OrgFreedesktopBolt1ManagerInterface; 0021 namespace Bolt 0022 { 0023 class Device; 0024 class KBOLT_EXPORT Manager : public QObject 0025 { 0026 Q_OBJECT 0027 0028 Q_PROPERTY(bool isAvailable READ isAvailable CONSTANT) 0029 Q_PROPERTY(uint version READ version CONSTANT STORED false) 0030 Q_PROPERTY(bool isProbing READ isProbing CONSTANT STORED false) 0031 Q_PROPERTY(Bolt::Policy defaultPolicy READ defaultPolicy CONSTANT STORED false) 0032 Q_PROPERTY(Bolt::Security securityLevel READ securityLevel CONSTANT STORED false) 0033 Q_PROPERTY(Bolt::AuthMode authMode READ authMode WRITE setAuthMode STORED false NOTIFY authModeChanged) 0034 0035 public: 0036 explicit Manager(QObject *parent = nullptr); 0037 ~Manager() override; 0038 0039 bool isAvailable() const; 0040 0041 uint version() const; 0042 bool isProbing() const; 0043 Policy defaultPolicy() const; 0044 Security securityLevel() const; 0045 AuthMode authMode() const; 0046 void setAuthMode(AuthMode mode); 0047 0048 /** 0049 * Updates device authorization and stores it persistently. 0050 */ 0051 void enrollDevice(const QString &uid, 0052 Bolt::Policy policy, 0053 Bolt::AuthFlags flags, 0054 std::function<void()> successCallback = {}, 0055 std::function<void(const QString &)> errorCallback = {}); 0056 /** 0057 * Keeps device authorized but removes it from persistent store. 0058 * 0059 * Next time the device is plugged in, it will not be authorized. 0060 */ 0061 void forgetDevice(const QString &uid, std::function<void()> successCallback = {}, std::function<void(const QString &)> errorCallback = {}); 0062 0063 Q_INVOKABLE QSharedPointer<Bolt::Device> device(const QString &uid) const; 0064 Q_INVOKABLE QSharedPointer<Bolt::Device> device(const QDBusObjectPath &path) const; 0065 Q_INVOKABLE QList<QSharedPointer<Bolt::Device>> devices() const; 0066 0067 Q_SIGNALS: 0068 void deviceAdded(const QSharedPointer<Bolt::Device> &device); 0069 void deviceRemoved(const QSharedPointer<Bolt::Device> &device); 0070 void authModeChanged(Bolt::AuthMode authMode); 0071 0072 private: 0073 QSharedPointer<Device> device(std::function<bool(const QSharedPointer<Device> &)> &&match) const; 0074 std::unique_ptr<OrgFreedesktopBolt1ManagerInterface> mInterface; 0075 0076 uint mVersion = 0; 0077 Policy mPolicy = Policy::Unknown; 0078 Security mSecurity = Security::Unknown; 0079 AuthMode mAuthMode = AuthMode::Disabled; 0080 bool mIsProbing = false; 0081 0082 QList<QSharedPointer<Device>> mDevices; 0083 }; 0084 0085 } // namespace 0086 0087 #endif