1 | /* |
---|---|
2 | SPDX-FileCopyrightText: Pranav Gade <pranavgade20@gmail.com> |
3 | |
4 | SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL |
5 | */ |
6 | |
7 | #include "tcsetting.h" |
8 | #include "tcsetting_p.h" |
9 | |
10 | #include <QDebug> |
11 | |
12 | #if !NM_CHECK_VERSION(1, 10, 0) |
13 | #define NM_SETTING_TC_CONFIG_SETTING_NAME "tc" |
14 | |
15 | #define NM_SETTING_TC_CONFIG_QDISCS "qdiscs" |
16 | #define NM_SETTING_TC_CONFIG_TFILTERS "tfilters" |
17 | #endif |
18 | |
19 | NetworkManager::TcSettingPrivate::TcSettingPrivate() |
20 | : name(NM_SETTING_TC_CONFIG_SETTING_NAME) |
21 | { |
22 | } |
23 | |
24 | NetworkManager::TcSetting::TcSetting() |
25 | : Setting(Setting::Tc) |
26 | , d_ptr(new TcSettingPrivate()) |
27 | { |
28 | } |
29 | |
30 | NetworkManager::TcSetting::TcSetting(const Ptr &other) |
31 | : Setting(other) |
32 | , d_ptr(new TcSettingPrivate()) |
33 | { |
34 | setQdiscs(other->qdiscs()); |
35 | setTfilters(other->tfilters()); |
36 | } |
37 | |
38 | NetworkManager::TcSetting::~TcSetting() |
39 | { |
40 | delete d_ptr; |
41 | } |
42 | |
43 | QString NetworkManager::TcSetting::name() const |
44 | { |
45 | Q_D(const TcSetting); |
46 | |
47 | return d->name; |
48 | } |
49 | |
50 | void NetworkManager::TcSetting::setQdiscs(const NMVariantMapList &qdiscs) |
51 | { |
52 | Q_D(TcSetting); |
53 | |
54 | d->qdiscs = qdiscs; |
55 | } |
56 | |
57 | NMVariantMapList NetworkManager::TcSetting::qdiscs() const |
58 | { |
59 | Q_D(const TcSetting); |
60 | |
61 | return d->qdiscs; |
62 | } |
63 | |
64 | void NetworkManager::TcSetting::setTfilters(const NMVariantMapList &tfilters) |
65 | { |
66 | Q_D(TcSetting); |
67 | |
68 | d->tfilters = tfilters; |
69 | } |
70 | |
71 | NMVariantMapList NetworkManager::TcSetting::tfilters() const |
72 | { |
73 | Q_D(const TcSetting); |
74 | |
75 | return d->tfilters; |
76 | } |
77 | |
78 | void NetworkManager::TcSetting::fromMap(const QVariantMap &setting) |
79 | { |
80 | if (setting.contains(key: QLatin1String(NM_SETTING_TC_CONFIG_QDISCS))) { |
81 | setQdiscs(qdbus_cast<NMVariantMapList>(v: setting.value(key: QLatin1String(NM_SETTING_TC_CONFIG_QDISCS)))); |
82 | } |
83 | |
84 | if (setting.contains(key: QLatin1String(NM_SETTING_TC_CONFIG_TFILTERS))) { |
85 | setTfilters(qdbus_cast<NMVariantMapList>(v: setting.value(key: QLatin1String(NM_SETTING_TC_CONFIG_TFILTERS)))); |
86 | } |
87 | } |
88 | |
89 | QVariantMap NetworkManager::TcSetting::toMap() const |
90 | { |
91 | QVariantMap setting; |
92 | |
93 | if (!qdiscs().empty()) { |
94 | setting.insert(key: QLatin1String(NM_SETTING_TC_CONFIG_QDISCS), value: QVariant::fromValue(value: qdiscs())); |
95 | } |
96 | |
97 | if (!tfilters().empty()) { |
98 | setting.insert(key: QLatin1String(NM_SETTING_TC_CONFIG_TFILTERS), value: QVariant::fromValue(value: tfilters())); |
99 | } |
100 | |
101 | return setting; |
102 | } |
103 | |
104 | QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::TcSetting &setting) |
105 | { |
106 | dbg.nospace() << "type: "<< setting.typeAsString(type: setting.type()) << '\n'; |
107 | dbg.nospace() << "initialized: "<< !setting.isNull() << '\n'; |
108 | |
109 | dbg.nospace() << NM_SETTING_TC_CONFIG_QDISCS << ": "<< '\n'; |
110 | const NMVariantMapList qdiscList = setting.qdiscs(); |
111 | for (const QVariantMap &qdisc : qdiscList) { |
112 | QVariantMap::const_iterator i = qdisc.constBegin(); |
113 | while (i != qdisc.constEnd()) { |
114 | dbg.nospace() << i.key() << ": "<< i.value() << '\n'; |
115 | } |
116 | } |
117 | dbg.nospace() << NM_SETTING_TC_CONFIG_TFILTERS << ": "<< '\n'; |
118 | const NMVariantMapList tfiltersList = setting.tfilters(); |
119 | for (const QVariantMap &tfilter : tfiltersList) { |
120 | QVariantMap::const_iterator i = tfilter.constBegin(); |
121 | while (i != tfilter.constEnd()) { |
122 | dbg.nospace() << i.key() << ": "<< i.value() << '\n'; |
123 | } |
124 | } |
125 | |
126 | return dbg.maybeSpace(); |
127 | } |
128 |