forked from linuxdeepin/udisks2-qt5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathudisks2_dbus_common.cpp
126 lines (104 loc) · 3.62 KB
/
udisks2_dbus_common.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// SPDX-FileCopyrightText: 2020 - 2022 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later
#include "udisks2_dbus_common.h"
#include "objectmanager_interface.h"
#include "udisks2_interface.h"
#include <QDBusArgument>
#include <QDBusInterface>
#include <QDBusConnection>
#include <QDBusReply>
#include <QXmlStreamReader>
namespace UDisks2 {
Q_GLOBAL_STATIC_WITH_ARGS(OrgFreedesktopDBusObjectManagerInterface, omGlobal, (UDISKS2_SERVICE, "/org/freedesktop/UDisks2", QDBusConnection::systemBus()))
Q_GLOBAL_STATIC_WITH_ARGS(OrgFreedesktopUDisks2ManagerInterface, umGlobal, (UDISKS2_SERVICE, "/org/freedesktop/UDisks2/Manager", QDBusConnection::systemBus()))
bool interfaceExists(const QString &path, const QString &interface)
{
QDBusInterface ud2(UDISKS2_SERVICE, path, "org.freedesktop.DBus.Introspectable", QDBusConnection::systemBus());
QDBusReply<QString> reply = ud2.call("Introspect");
QXmlStreamReader xml_parser(reply.value());
while (!xml_parser.atEnd()) {
xml_parser.readNext();
if (xml_parser.tokenType() == QXmlStreamReader::StartElement
&& xml_parser.name().toString() == "interface") {
const QString &name = xml_parser.attributes().value("name").toString();
if (name == interface) {
return true;
}
}
}
return false;
}
OrgFreedesktopDBusObjectManagerInterface *objectManager()
{
if (!omGlobal.exists()) {
qDBusRegisterMetaType<QMap<QString, QVariantMap>>();
qDBusRegisterMetaType<QList<QPair<QString, QVariantMap>>>();
qDBusRegisterMetaType<QByteArrayList>();
qDBusRegisterMetaType<QPair<QString,QVariantMap>>();
qDBusRegisterMetaType<QMap<QDBusObjectPath,QMap<QString,QVariantMap>>>();
QMetaType::registerDebugStreamOperator<QList<QPair<QString, QVariantMap>>>();
}
return omGlobal;
}
QString version()
{
return umGlobal->version();
}
QStringList supportedFilesystems()
{
return umGlobal->supportedFilesystems();
}
}
QDBusArgument &operator<<(QDBusArgument &argument, const UDisks2::SmartAttribute &mystruct)
{
argument.beginStructure();
argument << mystruct.id
<< mystruct.name
<< mystruct.flags
<< mystruct.value
<< mystruct.worst
<< mystruct.threshold
<< mystruct.pretty
<< mystruct.pretty_unit
<< mystruct.expansion;
argument.endStructure();
return argument;
}
const QDBusArgument &operator>>(const QDBusArgument &argument, UDisks2::SmartAttribute &mystruct)
{
argument.beginStructure();
argument >> mystruct.id
>> mystruct.name
>> mystruct.flags
>> mystruct.value
>> mystruct.worst
>> mystruct.threshold
>> mystruct.pretty
>> mystruct.pretty_unit
>> mystruct.expansion;
argument.endStructure();
return argument;
}
QDBusArgument &operator<<(QDBusArgument &argument, const UDisks2::ActiveDeviceInfo &mystruct)
{
argument.beginStructure();
argument << mystruct.block
<< mystruct.slot
<< mystruct.state
<< mystruct.num_read_errors
<< mystruct.expansion;
argument.endStructure();
return argument;
}
const QDBusArgument &operator>>(const QDBusArgument &argument, UDisks2::ActiveDeviceInfo &mystruct)
{
argument.beginStructure();
argument >> mystruct.block
>> mystruct.slot
>> mystruct.state
>> mystruct.num_read_errors
>> mystruct.expansion;
argument.endStructure();
return argument;
}