NetworkManagerQt

infinibandsetting.cpp
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
12NetworkManager::InfinibandSettingPrivate::InfinibandSettingPrivate()
13 : name(NM_SETTING_INFINIBAND_SETTING_NAME)
14 , mtu(0)
15 , transportMode(InfinibandSetting::Unknown)
16 , pKey(-1)
17{
18}
19
20NetworkManager::InfinibandSetting::InfinibandSetting()
21 : Setting(Setting::Infiniband)
22 , d_ptr(new InfinibandSettingPrivate())
23{
24}
25
26NetworkManager::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
37NetworkManager::InfinibandSetting::~InfinibandSetting()
38{
39 delete d_ptr;
40}
41
43{
45
46 return d->name;
47}
48
49void NetworkManager::InfinibandSetting::setMacAddress(const QByteArray &address)
50{
52
53 d->macAddress = address;
54}
55
56QByteArray NetworkManager::InfinibandSetting::macAddress() const
57{
58 Q_D(const InfinibandSetting);
59
60 return d->macAddress;
61}
62
63void NetworkManager::InfinibandSetting::setMtu(quint32 mtu)
64{
65 Q_D(InfinibandSetting);
66
67 d->mtu = mtu;
68}
69
70quint32 NetworkManager::InfinibandSetting::mtu() const
71{
72 Q_D(const InfinibandSetting);
73
74 return d->mtu;
75}
76
77void NetworkManager::InfinibandSetting::setTransportMode(NetworkManager::InfinibandSetting::TransportMode mode)
78{
79 Q_D(InfinibandSetting);
80
81 d->transportMode = mode;
82}
83
84NetworkManager::InfinibandSetting::TransportMode NetworkManager::InfinibandSetting::transportMode() const
85{
86 Q_D(const InfinibandSetting);
87
88 return d->transportMode;
89}
90
91void NetworkManager::InfinibandSetting::setPKey(qint32 key)
92{
93 Q_D(InfinibandSetting);
94
95 d->pKey = key;
96}
97
98qint32 NetworkManager::InfinibandSetting::pKey() const
99{
100 Q_D(const InfinibandSetting);
101
102 return d->pKey;
103}
104
105void NetworkManager::InfinibandSetting::setParent(const QString &parent)
106{
107 Q_D(InfinibandSetting);
108
109 d->parent = parent;
110}
111
112QString NetworkManager::InfinibandSetting::parent() const
113{
114 Q_D(const InfinibandSetting);
115
116 return d->parent;
117}
118
119void NetworkManager::InfinibandSetting::fromMap(const QVariantMap &setting)
120{
121 if (setting.contains(QLatin1String(NM_SETTING_INFINIBAND_MAC_ADDRESS))) {
122 setMacAddress(setting.value(QLatin1String(NM_SETTING_INFINIBAND_MAC_ADDRESS)).toByteArray());
123 }
124
125 if (setting.contains(QLatin1String(NM_SETTING_INFINIBAND_MTU))) {
126 setMtu(setting.value(QLatin1String(NM_SETTING_INFINIBAND_MTU)).toUInt());
127 }
128
129 if (setting.contains(QLatin1String(NM_SETTING_INFINIBAND_TRANSPORT_MODE))) {
130 QString mode = setting.value(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(QLatin1String(NM_SETTING_INFINIBAND_P_KEY))) {
140 setPKey(setting.value(QLatin1String(NM_SETTING_INFINIBAND_P_KEY)).toInt());
141 }
142
143 if (setting.contains(QLatin1String(NM_SETTING_INFINIBAND_PARENT))) {
144 setParent(setting.value(QLatin1String(NM_SETTING_INFINIBAND_PARENT)).toString());
145 }
146}
147
149{
150 QVariantMap setting;
151
152 if (!macAddress().isEmpty()) {
153 setting.insert(QLatin1String(NM_SETTING_INFINIBAND_MAC_ADDRESS), macAddress());
154 }
155
156 if (mtu()) {
157 setting.insert(QLatin1String(NM_SETTING_INFINIBAND_MTU), mtu());
158 }
159
160 if (transportMode() != Unknown) {
161 if (transportMode() == Datagram) {
162 setting.insert(QLatin1String(NM_SETTING_INFINIBAND_TRANSPORT_MODE), "datagram");
163 } else if (transportMode() == Connected) {
164 setting.insert(QLatin1String(NM_SETTING_INFINIBAND_TRANSPORT_MODE), "connected");
165 }
166 }
167
168 if (pKey() != -1) {
169 setting.insert(QLatin1String(NM_SETTING_INFINIBAND_P_KEY), pKey());
170 }
171
172 if (!parent().isEmpty()) {
173 setting.insert(QLatin1String(NM_SETTING_INFINIBAND_PARENT), parent());
174 }
175
176 return setting;
177}
178
179QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::InfinibandSetting &setting)
180{
181 dbg.nospace() << "type: " << setting.typeAsString(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}
Represents infiniband 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.
@ Connected
the system is currently connected to a network
Definition manager.h:40
@ Unknown
the networking system is not active or unable to report its status - proceed with caution
Definition manager.h:33
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 19 2024 11:56:22 by doxygen 1.11.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.