NetworkManagerQt

teamportsetting.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 "teamportsetting.h"
8#include "teamportsetting_p.h"
9
10#include <QDebug>
11
12#if !NM_CHECK_VERSION(1, 10, 0)
13#define NM_SETTING_TEAM_PORT_SETTING_NAME "team-port"
14
15#define NM_SETTING_TEAM_PORT_CONFIG "config"
16#define NM_SETTING_TEAM_PORT_QUEUE_ID "queue-id"
17#define NM_SETTING_TEAM_PORT_PRIO "prio"
18#define NM_SETTING_TEAM_PORT_STICKY "sticky"
19#define NM_SETTING_TEAM_PORT_LACP_PRIO "lacp-prio"
20#define NM_SETTING_TEAM_PORT_LACP_KEY "lacp-key"
21#define NM_SETTING_TEAM_PORT_LINK_WATCHERS "link-watchers"
22#endif
23
24NetworkManager::TeamPortSettingPrivate::TeamPortSettingPrivate()
25 : name(NM_SETTING_TEAM_PORT_SETTING_NAME)
26 , lacpKey(0)
27 , lacpPrio(255)
28 , prio(0)
29 , queueId(-1)
30 , sticky(false)
31{
32}
33
34NetworkManager::TeamPortSetting::TeamPortSetting()
35 : Setting(Setting::TeamPort)
36 , d_ptr(new TeamPortSettingPrivate())
37{
38}
39
40NetworkManager::TeamPortSetting::TeamPortSetting(const Ptr &other)
41 : Setting(other)
42 , d_ptr(new TeamPortSettingPrivate())
43{
44 config(other->config());
45 lacpKey(other->lacpKey());
46 lacpPrio(other->lacpPrio());
47 prio(other->prio());
48 queueId(other->queueId());
49 sticky(other->sticky());
50 setLinkWatchers(other->linkWatchers());
51}
52
53NetworkManager::TeamPortSetting::~TeamPortSetting()
54{
55 delete d_ptr;
56}
57
59{
60 Q_D(const TeamPortSetting);
61
62 return d->name;
63}
64
65void NetworkManager::TeamPortSetting::config(const QString &config)
66{
68
69 d->config = config;
70}
71
72QString NetworkManager::TeamPortSetting::config() const
73{
74 Q_D(const TeamPortSetting);
75
76 return d->config;
77}
78
79void NetworkManager::TeamPortSetting::lacpKey(qint32 key)
80{
81 Q_D(TeamPortSetting);
82
83 d->lacpKey = key;
84}
85
86qint32 NetworkManager::TeamPortSetting::lacpKey() const
87{
88 Q_D(const TeamPortSetting);
89
90 return d->lacpKey;
91}
92
93void NetworkManager::TeamPortSetting::lacpPrio(qint32 priority)
94{
95 Q_D(TeamPortSetting);
96
97 d->lacpPrio = priority;
98}
99
100qint32 NetworkManager::TeamPortSetting::lacpPrio() const
101{
102 Q_D(const TeamPortSetting);
103
104 return d->lacpPrio;
105}
106
107void NetworkManager::TeamPortSetting::prio(qint32 prio)
108{
109 Q_D(TeamPortSetting);
110
111 d->prio = prio;
112}
113
114qint32 NetworkManager::TeamPortSetting::prio() const
115{
116 Q_D(const TeamPortSetting);
117
118 return d->prio;
119}
120
121void NetworkManager::TeamPortSetting::queueId(qint32 id)
122{
123 Q_D(TeamPortSetting);
124
125 d->queueId = id;
126}
127
128qint32 NetworkManager::TeamPortSetting::queueId() const
129{
130 Q_D(const TeamPortSetting);
131
132 return d->queueId;
133}
134
135void NetworkManager::TeamPortSetting::sticky(bool sticky)
136{
137 Q_D(TeamPortSetting);
138
139 d->sticky = sticky;
140}
141
142bool NetworkManager::TeamPortSetting::sticky() const
143{
144 Q_D(const TeamPortSetting);
145
146 return d->sticky;
147}
148
149void NetworkManager::TeamPortSetting::setLinkWatchers(const NMVariantMapList &linkWatchers)
150{
151 Q_D(TeamPortSetting);
152
153 d->linkWatchers = linkWatchers;
154}
155
156NMVariantMapList NetworkManager::TeamPortSetting::linkWatchers() const
157{
158 Q_D(const TeamPortSetting);
159
160 return d->linkWatchers;
161}
162
163void NetworkManager::TeamPortSetting::fromMap(const QVariantMap &setting)
164{
165 if (setting.contains(QLatin1String(NM_SETTING_TEAM_PORT_CONFIG))) {
166 config(setting.value(QLatin1String(NM_SETTING_TEAM_PORT_CONFIG)).toString());
167 }
168
169 if (setting.contains(QLatin1String(NM_SETTING_TEAM_PORT_LACP_KEY))) {
170 lacpKey(setting.value(QLatin1String(NM_SETTING_TEAM_PORT_LACP_KEY)).toUInt());
171 }
172
173 if (setting.contains(QLatin1String(NM_SETTING_TEAM_PORT_LACP_PRIO))) {
174 lacpPrio(setting.value(QLatin1String(NM_SETTING_TEAM_PORT_LACP_PRIO)).toUInt());
175 }
176
177 if (setting.contains(QLatin1String(NM_SETTING_TEAM_PORT_PRIO))) {
178 prio(setting.value(QLatin1String(NM_SETTING_TEAM_PORT_PRIO)).toUInt());
179 }
180
181 if (setting.contains(QLatin1String(NM_SETTING_TEAM_PORT_QUEUE_ID))) {
182 queueId(setting.value(QLatin1String(NM_SETTING_TEAM_PORT_QUEUE_ID)).toUInt());
183 }
184
185 if (setting.contains(QLatin1String(NM_SETTING_TEAM_PORT_STICKY))) {
186 sticky(setting.value(QLatin1String(NM_SETTING_TEAM_PORT_STICKY)).toBool());
187 }
188
189 if (setting.contains(QLatin1String(NM_SETTING_TEAM_PORT_LINK_WATCHERS))) {
190 setLinkWatchers(qdbus_cast<NMVariantMapList>(setting.value(QLatin1String(NM_SETTING_TEAM_PORT_LINK_WATCHERS))));
191 }
192}
193
195{
196 QVariantMap setting;
197
198 if (!config().isEmpty()) {
199 setting.insert(QLatin1String(NM_SETTING_TEAM_PORT_CONFIG), config());
200 }
201
202 if (lacpKey() != 0) {
203 setting.insert(QLatin1String(NM_SETTING_TEAM_PORT_LACP_KEY), lacpKey());
204 }
205
206 if (lacpPrio() != 255) {
207 setting.insert(QLatin1String(NM_SETTING_TEAM_PORT_LACP_PRIO), lacpPrio());
208 }
209
210 if (prio() != 0) {
211 setting.insert(QLatin1String(NM_SETTING_TEAM_PORT_PRIO), prio());
212 }
213
214 if (queueId() != -1) {
215 setting.insert(QLatin1String(NM_SETTING_TEAM_PORT_QUEUE_ID), queueId());
216 }
217
218 if (sticky()) {
219 setting.insert(QLatin1String(NM_SETTING_TEAM_PORT_STICKY), sticky());
220 }
221
222 if (!linkWatchers().empty()) {
223 setting.insert(QLatin1String(NM_SETTING_TEAM_PORT_LINK_WATCHERS), QVariant::fromValue(linkWatchers()));
224 }
225
226 return setting;
227}
228
229QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::TeamPortSetting &setting)
230{
231 dbg.nospace() << "type: " << setting.typeAsString(setting.type()) << '\n';
232 dbg.nospace() << "initialized: " << !setting.isNull() << '\n';
233
234 dbg.nospace() << NM_SETTING_TEAM_PORT_CONFIG << ": " << setting.config() << '\n';
235 dbg.nospace() << NM_SETTING_TEAM_PORT_LACP_KEY << ": " << setting.lacpKey() << '\n';
236 dbg.nospace() << NM_SETTING_TEAM_PORT_LACP_PRIO << ": " << setting.lacpPrio() << '\n';
237 dbg.nospace() << NM_SETTING_TEAM_PORT_PRIO << ": " << setting.prio() << '\n';
238 dbg.nospace() << NM_SETTING_TEAM_PORT_QUEUE_ID << ": " << setting.queueId() << '\n';
239 dbg.nospace() << NM_SETTING_TEAM_PORT_STICKY << ": " << setting.sticky() << '\n';
240
241 dbg.nospace() << NM_SETTING_TEAM_PORT_LINK_WATCHERS << ": " << '\n';
242 const NMVariantMapList variantMapList = setting.linkWatchers();
243 for (const QVariantMap &linkWatcher : variantMapList) {
244 QVariantMap::const_iterator i = linkWatcher.constBegin();
245 while (i != linkWatcher.constEnd()) {
246 dbg.nospace() << i.key() << ": " << i.value() << '\n';
247 }
248 }
249
250 return dbg.maybeSpace();
251}
Represents TeamPort setting.
QVariantMap toMap() const override
Must be reimplemented, default implementationd does nothing.
void fromMap(const QVariantMap &setting) override
Must be reimplemented, default implementation does nothing.
QString name() const override
Must be reimplemented, default implementationd does nothing.
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 Dec 20 2024 11:59:05 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.