NetworkManagerQt

tcsetting.cpp
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
19NetworkManager::TcSettingPrivate::TcSettingPrivate()
20 : name(NM_SETTING_TC_CONFIG_SETTING_NAME)
21{
22}
23
24NetworkManager::TcSetting::TcSetting()
25 : Setting(Setting::Tc)
26 , d_ptr(new TcSettingPrivate())
27{
28}
29
30NetworkManager::TcSetting::TcSetting(const Ptr &other)
31 : Setting(other)
32 , d_ptr(new TcSettingPrivate())
33{
34 setQdiscs(other->qdiscs());
35 setTfilters(other->tfilters());
36}
37
38NetworkManager::TcSetting::~TcSetting()
39{
40 delete d_ptr;
41}
42
44{
45 Q_D(const TcSetting);
46
47 return d->name;
48}
49
50void NetworkManager::TcSetting::setQdiscs(const NMVariantMapList &qdiscs)
51{
53
54 d->qdiscs = qdiscs;
55}
56
57NMVariantMapList NetworkManager::TcSetting::qdiscs() const
58{
59 Q_D(const TcSetting);
60
61 return d->qdiscs;
62}
63
64void NetworkManager::TcSetting::setTfilters(const NMVariantMapList &tfilters)
65{
66 Q_D(TcSetting);
67
68 d->tfilters = tfilters;
69}
70
71NMVariantMapList NetworkManager::TcSetting::tfilters() const
72{
73 Q_D(const TcSetting);
74
75 return d->tfilters;
76}
77
78void NetworkManager::TcSetting::fromMap(const QVariantMap &setting)
79{
80 if (setting.contains(QLatin1String(NM_SETTING_TC_CONFIG_QDISCS))) {
81 setQdiscs(qdbus_cast<NMVariantMapList>(setting.value(QLatin1String(NM_SETTING_TC_CONFIG_QDISCS))));
82 }
83
84 if (setting.contains(QLatin1String(NM_SETTING_TC_CONFIG_TFILTERS))) {
85 setTfilters(qdbus_cast<NMVariantMapList>(setting.value(QLatin1String(NM_SETTING_TC_CONFIG_TFILTERS))));
86 }
87}
88
90{
91 QVariantMap setting;
92
93 if (!qdiscs().empty()) {
94 setting.insert(QLatin1String(NM_SETTING_TC_CONFIG_QDISCS), QVariant::fromValue(qdiscs()));
95 }
96
97 if (!tfilters().empty()) {
98 setting.insert(QLatin1String(NM_SETTING_TC_CONFIG_TFILTERS), QVariant::fromValue(tfilters()));
99 }
100
101 return setting;
102}
103
104QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::TcSetting &setting)
105{
106 dbg.nospace() << "type: " << setting.typeAsString(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}
Represents Tc setting.
Definition tcsetting.h:21
QVariantMap toMap() const override
Must be reimplemented, default implementationd does nothing.
Definition tcsetting.cpp:89
void fromMap(const QVariantMap &setting) override
Must be reimplemented, default implementation does nothing.
Definition tcsetting.cpp:78
QString name() const override
Must be reimplemented, default implementationd does nothing.
Definition tcsetting.cpp:43
QDebug & maybeSpace()
QDebug & nospace()
QVariant fromValue(T &&value)
Q_D(Todo)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:01:06 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.