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 "infinibandsetting.h" |
8 | #include "infinibandsetting_p.h" |
9 | |
10 | #include <QDebug> |
11 | |
12 | NetworkManager::InfinibandSettingPrivate::InfinibandSettingPrivate() |
13 | : name(NM_SETTING_INFINIBAND_SETTING_NAME) |
14 | , mtu(0) |
15 | , transportMode(InfinibandSetting::Unknown) |
16 | , pKey(-1) |
17 | { |
18 | } |
19 | |
20 | NetworkManager::InfinibandSetting::InfinibandSetting() |
21 | : Setting(Setting::Infiniband) |
22 | , d_ptr(new InfinibandSettingPrivate()) |
23 | { |
24 | } |
25 | |
26 | NetworkManager::InfinibandSetting::InfinibandSetting(const NetworkManager::InfinibandSetting::Ptr &other) |
27 | : Setting(other) |
28 | , d_ptr(new InfinibandSettingPrivate()) |
29 | { |
30 | setMacAddress(other->macAddress()); |
31 | setMtu(other->mtu()); |
32 | setTransportMode(other->transportMode()); |
33 | setPKey(other->pKey()); |
34 | setParent(other->parent()); |
35 | } |
36 | |
37 | NetworkManager::InfinibandSetting::~InfinibandSetting() |
38 | { |
39 | delete d_ptr; |
40 | } |
41 | |
42 | QString NetworkManager::InfinibandSetting::name() const |
43 | { |
44 | Q_D(const InfinibandSetting); |
45 | |
46 | return d->name; |
47 | } |
48 | |
49 | void NetworkManager::InfinibandSetting::setMacAddress(const QByteArray &address) |
50 | { |
51 | Q_D(InfinibandSetting); |
52 | |
53 | d->macAddress = address; |
54 | } |
55 | |
56 | QByteArray NetworkManager::InfinibandSetting::macAddress() const |
57 | { |
58 | Q_D(const InfinibandSetting); |
59 | |
60 | return d->macAddress; |
61 | } |
62 | |
63 | void NetworkManager::InfinibandSetting::setMtu(quint32 mtu) |
64 | { |
65 | Q_D(InfinibandSetting); |
66 | |
67 | d->mtu = mtu; |
68 | } |
69 | |
70 | quint32 NetworkManager::InfinibandSetting::mtu() const |
71 | { |
72 | Q_D(const InfinibandSetting); |
73 | |
74 | return d->mtu; |
75 | } |
76 | |
77 | void NetworkManager::InfinibandSetting::setTransportMode(NetworkManager::InfinibandSetting::TransportMode mode) |
78 | { |
79 | Q_D(InfinibandSetting); |
80 | |
81 | d->transportMode = mode; |
82 | } |
83 | |
84 | NetworkManager::InfinibandSetting::TransportMode NetworkManager::InfinibandSetting::transportMode() const |
85 | { |
86 | Q_D(const InfinibandSetting); |
87 | |
88 | return d->transportMode; |
89 | } |
90 | |
91 | void NetworkManager::InfinibandSetting::setPKey(qint32 key) |
92 | { |
93 | Q_D(InfinibandSetting); |
94 | |
95 | d->pKey = key; |
96 | } |
97 | |
98 | qint32 NetworkManager::InfinibandSetting::pKey() const |
99 | { |
100 | Q_D(const InfinibandSetting); |
101 | |
102 | return d->pKey; |
103 | } |
104 | |
105 | void NetworkManager::InfinibandSetting::setParent(const QString &parent) |
106 | { |
107 | Q_D(InfinibandSetting); |
108 | |
109 | d->parent = parent; |
110 | } |
111 | |
112 | QString NetworkManager::InfinibandSetting::parent() const |
113 | { |
114 | Q_D(const InfinibandSetting); |
115 | |
116 | return d->parent; |
117 | } |
118 | |
119 | void NetworkManager::InfinibandSetting::fromMap(const QVariantMap &setting) |
120 | { |
121 | if (setting.contains(key: QLatin1String(NM_SETTING_INFINIBAND_MAC_ADDRESS))) { |
122 | setMacAddress(setting.value(key: QLatin1String(NM_SETTING_INFINIBAND_MAC_ADDRESS)).toByteArray()); |
123 | } |
124 | |
125 | if (setting.contains(key: QLatin1String(NM_SETTING_INFINIBAND_MTU))) { |
126 | setMtu(setting.value(key: QLatin1String(NM_SETTING_INFINIBAND_MTU)).toUInt()); |
127 | } |
128 | |
129 | if (setting.contains(key: QLatin1String(NM_SETTING_INFINIBAND_TRANSPORT_MODE))) { |
130 | QString mode = setting.value(key: QLatin1String(NM_SETTING_INFINIBAND_TRANSPORT_MODE)).toString(); |
131 | |
132 | if (mode == "datagram" ) { |
133 | setTransportMode(Datagram); |
134 | } else if (mode == "connected" ) { |
135 | setTransportMode(Connected); |
136 | } |
137 | } |
138 | |
139 | if (setting.contains(key: QLatin1String(NM_SETTING_INFINIBAND_P_KEY))) { |
140 | setPKey(setting.value(key: QLatin1String(NM_SETTING_INFINIBAND_P_KEY)).toInt()); |
141 | } |
142 | |
143 | if (setting.contains(key: QLatin1String(NM_SETTING_INFINIBAND_PARENT))) { |
144 | setParent(setting.value(key: QLatin1String(NM_SETTING_INFINIBAND_PARENT)).toString()); |
145 | } |
146 | } |
147 | |
148 | QVariantMap NetworkManager::InfinibandSetting::toMap() const |
149 | { |
150 | QVariantMap setting; |
151 | |
152 | if (!macAddress().isEmpty()) { |
153 | setting.insert(key: QLatin1String(NM_SETTING_INFINIBAND_MAC_ADDRESS), value: macAddress()); |
154 | } |
155 | |
156 | if (mtu()) { |
157 | setting.insert(key: QLatin1String(NM_SETTING_INFINIBAND_MTU), value: mtu()); |
158 | } |
159 | |
160 | if (transportMode() != Unknown) { |
161 | if (transportMode() == Datagram) { |
162 | setting.insert(key: QLatin1String(NM_SETTING_INFINIBAND_TRANSPORT_MODE), value: "datagram" ); |
163 | } else if (transportMode() == Connected) { |
164 | setting.insert(key: QLatin1String(NM_SETTING_INFINIBAND_TRANSPORT_MODE), value: "connected" ); |
165 | } |
166 | } |
167 | |
168 | if (pKey() != -1) { |
169 | setting.insert(key: QLatin1String(NM_SETTING_INFINIBAND_P_KEY), value: pKey()); |
170 | } |
171 | |
172 | if (!parent().isEmpty()) { |
173 | setting.insert(key: QLatin1String(NM_SETTING_INFINIBAND_PARENT), value: parent()); |
174 | } |
175 | |
176 | return setting; |
177 | } |
178 | |
179 | QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::InfinibandSetting &setting) |
180 | { |
181 | dbg.nospace() << "type: " << setting.typeAsString(type: setting.type()) << '\n'; |
182 | dbg.nospace() << "initialized: " << !setting.isNull() << '\n'; |
183 | |
184 | dbg.nospace() << NM_SETTING_INFINIBAND_MAC_ADDRESS << ": " << setting.macAddress() << '\n'; |
185 | dbg.nospace() << NM_SETTING_INFINIBAND_MTU << ": " << setting.mtu() << '\n'; |
186 | dbg.nospace() << NM_SETTING_INFINIBAND_TRANSPORT_MODE << ": " << setting.transportMode() << '\n'; |
187 | dbg.nospace() << NM_SETTING_INFINIBAND_P_KEY << ": " << setting.pKey() << '\n'; |
188 | dbg.nospace() << NM_SETTING_INFINIBAND_PARENT << ": " << setting.parent() << '\n'; |
189 | |
190 | return dbg.maybeSpace(); |
191 | } |
192 | |