1 | /* |
---|---|
2 | SPDX-FileCopyrightText: 2012-2013 Jan Grulich <jgrulich@redhat.com> |
3 | |
4 | SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL |
5 | */ |
6 | |
7 | #include "bridgeportsetting.h" |
8 | #include "bridgeportsetting_p.h" |
9 | |
10 | #include <QDebug> |
11 | |
12 | NetworkManager::BridgePortSettingPrivate::BridgePortSettingPrivate() |
13 | : name(NM_SETTING_BRIDGE_PORT_SETTING_NAME) |
14 | , priority(32) |
15 | , pathCost(100) |
16 | , hairpinMode(false) |
17 | { |
18 | } |
19 | |
20 | NetworkManager::BridgePortSetting::BridgePortSetting() |
21 | : Setting(Setting::BridgePort) |
22 | , d_ptr(new BridgePortSettingPrivate()) |
23 | { |
24 | } |
25 | |
26 | NetworkManager::BridgePortSetting::BridgePortSetting(const NetworkManager::BridgePortSetting::Ptr &other) |
27 | : Setting(other) |
28 | , d_ptr(new BridgePortSettingPrivate()) |
29 | { |
30 | setPriority(other->priority()); |
31 | setPathCost(other->pathCost()); |
32 | setHairpinMode(other->hairpinMode()); |
33 | } |
34 | |
35 | NetworkManager::BridgePortSetting::~BridgePortSetting() |
36 | { |
37 | delete d_ptr; |
38 | } |
39 | |
40 | QString NetworkManager::BridgePortSetting::name() const |
41 | { |
42 | Q_D(const BridgePortSetting); |
43 | |
44 | return d->name; |
45 | } |
46 | |
47 | void NetworkManager::BridgePortSetting::setPriority(quint32 priority) |
48 | { |
49 | Q_D(BridgePortSetting); |
50 | |
51 | d->priority = priority; |
52 | } |
53 | |
54 | quint32 NetworkManager::BridgePortSetting::priority() const |
55 | { |
56 | Q_D(const BridgePortSetting); |
57 | |
58 | return d->priority; |
59 | } |
60 | |
61 | void NetworkManager::BridgePortSetting::setPathCost(quint32 cost) |
62 | { |
63 | Q_D(BridgePortSetting); |
64 | |
65 | d->pathCost = cost; |
66 | } |
67 | |
68 | quint32 NetworkManager::BridgePortSetting::pathCost() const |
69 | { |
70 | Q_D(const BridgePortSetting); |
71 | |
72 | return d->pathCost; |
73 | } |
74 | |
75 | void NetworkManager::BridgePortSetting::setHairpinMode(bool enable) |
76 | { |
77 | Q_D(BridgePortSetting); |
78 | |
79 | d->hairpinMode = enable; |
80 | } |
81 | |
82 | bool NetworkManager::BridgePortSetting::hairpinMode() const |
83 | { |
84 | Q_D(const BridgePortSetting); |
85 | |
86 | return d->hairpinMode; |
87 | } |
88 | |
89 | void NetworkManager::BridgePortSetting::fromMap(const QVariantMap &setting) |
90 | { |
91 | if (setting.contains(key: QLatin1String(NM_SETTING_BRIDGE_PORT_PRIORITY))) { |
92 | setPriority(setting.value(key: QLatin1String(NM_SETTING_BRIDGE_PORT_PRIORITY)).toUInt()); |
93 | } |
94 | |
95 | if (setting.contains(key: QLatin1String(NM_SETTING_BRIDGE_PORT_PATH_COST))) { |
96 | setPathCost(setting.value(key: QLatin1String(NM_SETTING_BRIDGE_PORT_PATH_COST)).toUInt()); |
97 | } |
98 | |
99 | if (setting.contains(key: QLatin1String(NM_SETTING_BRIDGE_PORT_HAIRPIN_MODE))) { |
100 | setHairpinMode(setting.value(key: QLatin1String(NM_SETTING_BRIDGE_PORT_HAIRPIN_MODE)).toBool()); |
101 | } |
102 | } |
103 | |
104 | QVariantMap NetworkManager::BridgePortSetting::toMap() const |
105 | { |
106 | QVariantMap setting; |
107 | |
108 | if (priority() != 32) { |
109 | setting.insert(key: QLatin1String(NM_SETTING_BRIDGE_PORT_PRIORITY), value: priority()); |
110 | } |
111 | |
112 | if (pathCost() != 100) { |
113 | setting.insert(key: QLatin1String(NM_SETTING_BRIDGE_PORT_PATH_COST), value: pathCost()); |
114 | } |
115 | |
116 | if (hairpinMode()) { |
117 | setting.insert(key: QLatin1String(NM_SETTING_BRIDGE_PORT_PATH_COST), value: hairpinMode()); |
118 | } |
119 | |
120 | return setting; |
121 | } |
122 | |
123 | QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::BridgePortSetting &setting) |
124 | { |
125 | dbg.nospace() << "type: "<< setting.typeAsString(type: setting.type()) << '\n'; |
126 | dbg.nospace() << "initialized: "<< !setting.isNull() << '\n'; |
127 | |
128 | dbg.nospace() << NM_SETTING_BRIDGE_PORT_PRIORITY << ": "<< setting.priority() << '\n'; |
129 | dbg.nospace() << NM_SETTING_BRIDGE_PORT_PATH_COST << ": "<< setting.pathCost() << '\n'; |
130 | dbg.nospace() << NM_SETTING_BRIDGE_PORT_PATH_COST << ": "<< setting.hairpinMode() << '\n'; |
131 | |
132 | return dbg.maybeSpace(); |
133 | } |
134 |