Changeset View
Changeset View
Standalone View
Standalone View
autotests/bolt/fakeserver/fakemanager.h
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright (c) 2018 Daniel Vrátil <dvratil@kde.org> | ||||
3 | * | ||||
4 | * This program is free software; you can redistribute it and/or | ||||
5 | * modify it under the terms of the GNU General Public License as | ||||
6 | * published by the Free Software Foundation; either version 2 of | ||||
7 | * the License or (at your option) version 3 or any later version | ||||
8 | * accepted by the membership of KDE e.V. (or its successor approved | ||||
9 | * by the membership of KDE e.V.), which shall act as a proxy | ||||
10 | * defined in Section 14 of version 3 of the license. | ||||
11 | * | ||||
12 | * This program is distributed in the hope that it will be useful, | ||||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
15 | * GNU General Public License for more details. | ||||
16 | * | ||||
17 | * You should have received a copy of the GNU General Public License | ||||
18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
19 | */ | ||||
20 | | ||||
21 | #ifndef FAKEMANAGER_H_ | ||||
22 | #define FAKEMANAGER_H_ | ||||
23 | | ||||
24 | #include <QObject> | ||||
25 | #include <QDBusObjectPath> | ||||
26 | #include <QList> | ||||
27 | #include <QString> | ||||
28 | #include <QJsonObject> | ||||
29 | | ||||
30 | #include <memory> | ||||
31 | | ||||
32 | class FakeManagerException : public std::runtime_error | ||||
33 | { | ||||
34 | public: | ||||
35 | FakeManagerException(const QString &what) | ||||
36 | : std::runtime_error(what.toStdString()) | ||||
37 | {} | ||||
38 | }; | ||||
39 | | ||||
40 | class FakeDevice; | ||||
41 | class FakeManager : public QObject | ||||
42 | { | ||||
43 | Q_OBJECT | ||||
44 | Q_CLASSINFO("D-Bus Interface", "org.freedesktop.bolt1.Manager") | ||||
45 | | ||||
46 | Q_PROPERTY(unsigned int Version READ version CONSTANT) | ||||
47 | Q_PROPERTY(bool Probing READ isProbing CONSTANT) | ||||
48 | Q_PROPERTY(QString DefaultPolicy READ defaultPolicy CONSTANT) | ||||
49 | Q_PROPERTY(QString SecurityLevel READ securityLevel CONSTANT) | ||||
50 | Q_PROPERTY(QString AuthMode READ authMode WRITE setAuthMode) | ||||
51 | public: | ||||
52 | explicit FakeManager(const QJsonObject &json, QObject *parent = nullptr); | ||||
53 | explicit FakeManager(QObject *parent = nullptr); | ||||
54 | ~FakeManager() override; | ||||
55 | | ||||
56 | unsigned int version() const; | ||||
57 | bool isProbing() const; | ||||
58 | QString defaultPolicy() const; | ||||
59 | QString securityLevel() const; | ||||
60 | QString authMode() const; | ||||
61 | void setAuthMode(const QString &authMode); | ||||
62 | | ||||
63 | FakeDevice *addDevice(std::unique_ptr<FakeDevice> device); | ||||
64 | void removeDevice(const QString &uid); | ||||
65 | QList<FakeDevice *> devices() const; | ||||
66 | | ||||
67 | public Q_SLOTS: | ||||
68 | QList<QDBusObjectPath> ListDevices() const; | ||||
69 | QDBusObjectPath DeviceByUid(const QString &uid) const; | ||||
70 | QDBusObjectPath EnrollDevice(const QString &uid, const QString &policy, const QString &flags); | ||||
71 | void ForgetDevice(const QString &uid); | ||||
72 | | ||||
73 | Q_SIGNALS: | ||||
74 | void DeviceAdded(const QDBusObjectPath &device); | ||||
75 | void DeviceRemoved(const QDBusObjectPath &device); | ||||
76 | | ||||
77 | private: | ||||
78 | bool mProbing = false; | ||||
79 | QString mDefaultPolicy = QStringLiteral("auto"); | ||||
80 | QString mSecurityLevel = QStringLiteral("none"); | ||||
81 | QString mAuthMode = QStringLiteral("enabled"); | ||||
82 | | ||||
83 | QMap<QString /*uid*/, FakeDevice*> mDevices; | ||||
84 | }; | ||||
85 | | ||||
86 | | ||||
87 | #endif |