NetworkManagerQt

ovsbridgesetting.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 "ovsbridgesetting.h"
8#include "ovsbridgesetting_p.h"
9
10#include <QDebug>
11
12#if !NM_CHECK_VERSION(1, 10, 0)
13#define NM_SETTING_OVS_BRIDGE_SETTING_NAME "ovs-bridge"
14#define NM_SETTING_OVS_BRIDGE_FAIL_MODE "fail-mode"
15#define NM_SETTING_OVS_BRIDGE_MCAST_SNOOPING_ENABLE "mcast-snooping-enable"
16#define NM_SETTING_OVS_BRIDGE_RSTP_ENABLE "rstp-enable"
17#define NM_SETTING_OVS_BRIDGE_STP_ENABLE "stp-enable"
18#endif
19
20NetworkManager::OvsBridgeSettingPrivate::OvsBridgeSettingPrivate()
21 : name(NM_SETTING_OVS_BRIDGE_SETTING_NAME)
22 , mcastSnoopingEnable(false)
23 , rstpEnable(false)
24 , stpEnable(false)
25{
26}
27
28NetworkManager::OvsBridgeSetting::OvsBridgeSetting()
29 : Setting(Setting::OvsBridge)
30 , d_ptr(new OvsBridgeSettingPrivate())
31{
32}
33
34NetworkManager::OvsBridgeSetting::OvsBridgeSetting(const Ptr &other)
35 : Setting(other)
36 , d_ptr(new OvsBridgeSettingPrivate())
37{
38 setFailMode(other->failMode());
39 setMcastSnoopingEnable(other->mcastSnoopingEnable());
40 setRstpEnable(other->rstpEnable());
41 setStpEnable(other->stpEnable());
42}
43
44NetworkManager::OvsBridgeSetting::~OvsBridgeSetting()
45{
46 delete d_ptr;
47}
48
50{
51 Q_D(const OvsBridgeSetting);
52
53 return d->name;
54}
55
56void NetworkManager::OvsBridgeSetting::setMcastSnoopingEnable(bool mcastSnoopingEnable)
57{
59
60 d->mcastSnoopingEnable = mcastSnoopingEnable;
61}
62
63bool NetworkManager::OvsBridgeSetting::mcastSnoopingEnable() const
64{
65 Q_D(const OvsBridgeSetting);
66
67 return d->mcastSnoopingEnable;
68}
69
70void NetworkManager::OvsBridgeSetting::setRstpEnable(bool rstpEnable)
71{
72 Q_D(OvsBridgeSetting);
73
74 d->rstpEnable = rstpEnable;
75}
76
77bool NetworkManager::OvsBridgeSetting::rstpEnable() const
78{
79 Q_D(const OvsBridgeSetting);
80
81 return d->rstpEnable;
82}
83
84void NetworkManager::OvsBridgeSetting::setStpEnable(bool stpEnable)
85{
86 Q_D(OvsBridgeSetting);
87
88 d->stpEnable = stpEnable;
89}
90
91bool NetworkManager::OvsBridgeSetting::stpEnable() const
92{
93 Q_D(const OvsBridgeSetting);
94
95 return d->stpEnable;
96}
97
98void NetworkManager::OvsBridgeSetting::setFailMode(const QString &mode)
99{
100 Q_D(OvsBridgeSetting);
101
102 d->failMode = mode;
103}
104
105QString NetworkManager::OvsBridgeSetting::failMode() const
106{
107 Q_D(const OvsBridgeSetting);
108
109 return d->failMode;
110}
111
112void NetworkManager::OvsBridgeSetting::fromMap(const QVariantMap &setting)
113{
114 if (setting.contains(QLatin1String(NM_SETTING_OVS_BRIDGE_MCAST_SNOOPING_ENABLE))) {
115 setMcastSnoopingEnable(setting.value(QLatin1String(NM_SETTING_OVS_BRIDGE_MCAST_SNOOPING_ENABLE)).toBool());
116 }
117
118 if (setting.contains(QLatin1String(NM_SETTING_OVS_BRIDGE_RSTP_ENABLE))) {
119 setRstpEnable(setting.value(QLatin1String(NM_SETTING_OVS_BRIDGE_RSTP_ENABLE)).toBool());
120 }
121
122 if (setting.contains(QLatin1String(NM_SETTING_OVS_BRIDGE_STP_ENABLE))) {
123 setStpEnable(setting.value(QLatin1String(NM_SETTING_OVS_BRIDGE_STP_ENABLE)).toBool());
124 }
125
126 if (setting.contains(QLatin1String(NM_SETTING_OVS_BRIDGE_FAIL_MODE))) {
127 setFailMode(setting.value(QLatin1String(NM_SETTING_OVS_BRIDGE_FAIL_MODE)).toString());
128 }
129}
130
132{
133 QVariantMap setting;
134
135 setting.insert(QLatin1String(NM_SETTING_OVS_BRIDGE_MCAST_SNOOPING_ENABLE), mcastSnoopingEnable());
136 setting.insert(QLatin1String(NM_SETTING_OVS_BRIDGE_RSTP_ENABLE), rstpEnable());
137 setting.insert(QLatin1String(NM_SETTING_OVS_BRIDGE_STP_ENABLE), stpEnable());
138
139 if (!failMode().isEmpty()) {
140 setting.insert(QLatin1String(NM_SETTING_OVS_BRIDGE_FAIL_MODE), failMode());
141 }
142
143 return setting;
144}
145
146QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::OvsBridgeSetting &setting)
147{
148 dbg.nospace() << "type: " << setting.typeAsString(setting.type()) << '\n';
149 dbg.nospace() << "initialized: " << !setting.isNull() << '\n';
150
151 dbg.nospace() << NM_SETTING_OVS_BRIDGE_MCAST_SNOOPING_ENABLE << ": " << setting.mcastSnoopingEnable() << '\n';
152 dbg.nospace() << NM_SETTING_OVS_BRIDGE_RSTP_ENABLE << ": " << setting.rstpEnable() << '\n';
153 dbg.nospace() << NM_SETTING_OVS_BRIDGE_STP_ENABLE << ": " << setting.stpEnable() << '\n';
154 dbg.nospace() << NM_SETTING_OVS_BRIDGE_FAIL_MODE << ": " << setting.failMode() << '\n';
155
156 return dbg.maybeSpace();
157}
Represents ovs-bridge setting.
void fromMap(const QVariantMap &setting) override
Must be reimplemented, default implementation does nothing.
QString name() const override
Must be reimplemented, default implementationd does nothing.
QVariantMap toMap() const override
Must be reimplemented, default implementationd does nothing.
QDebug & maybeSpace()
QDebug & nospace()
Q_D(Todo)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jul 12 2024 11:50:42 by doxygen 1.11.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.