| 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 "bondsetting.h" |
| 8 | #include "bondsetting_p.h" |
| 9 | |
| 10 | #define NM_SETTING_BOND_INTERFACE_NAME "interface-name" |
| 11 | |
| 12 | #include <QDebug> |
| 13 | |
| 14 | NetworkManager::BondSettingPrivate::BondSettingPrivate() |
| 15 | : name(NM_SETTING_BOND_SETTING_NAME) |
| 16 | { |
| 17 | } |
| 18 | |
| 19 | NetworkManager::BondSetting::BondSetting() |
| 20 | : Setting(Setting::Bond) |
| 21 | , d_ptr(new BondSettingPrivate()) |
| 22 | { |
| 23 | } |
| 24 | |
| 25 | NetworkManager::BondSetting::BondSetting(const Ptr &other) |
| 26 | : Setting(other) |
| 27 | , d_ptr(new BondSettingPrivate()) |
| 28 | { |
| 29 | setInterfaceName(other->interfaceName()); |
| 30 | setOptions(other->options()); |
| 31 | } |
| 32 | |
| 33 | NetworkManager::BondSetting::~BondSetting() |
| 34 | { |
| 35 | delete d_ptr; |
| 36 | } |
| 37 | |
| 38 | QString NetworkManager::BondSetting::name() const |
| 39 | { |
| 40 | Q_D(const BondSetting); |
| 41 | |
| 42 | return d->name; |
| 43 | } |
| 44 | |
| 45 | void NetworkManager::BondSetting::setInterfaceName(const QString &name) |
| 46 | { |
| 47 | Q_D(BondSetting); |
| 48 | |
| 49 | d->interfaceName = name; |
| 50 | } |
| 51 | |
| 52 | QString NetworkManager::BondSetting::interfaceName() const |
| 53 | { |
| 54 | Q_D(const BondSetting); |
| 55 | |
| 56 | return d->interfaceName; |
| 57 | } |
| 58 | |
| 59 | void NetworkManager::BondSetting::addOption(const QString &option, const QString &value) |
| 60 | { |
| 61 | Q_D(BondSetting); |
| 62 | |
| 63 | d->options.insert(key: option, value); |
| 64 | } |
| 65 | |
| 66 | void NetworkManager::BondSetting::setOptions(const NMStringMap &options) |
| 67 | { |
| 68 | Q_D(BondSetting); |
| 69 | |
| 70 | d->options = options; |
| 71 | } |
| 72 | |
| 73 | NMStringMap NetworkManager::BondSetting::options() const |
| 74 | { |
| 75 | Q_D(const BondSetting); |
| 76 | |
| 77 | return d->options; |
| 78 | } |
| 79 | |
| 80 | void NetworkManager::BondSetting::fromMap(const QVariantMap &setting) |
| 81 | { |
| 82 | if (setting.contains(key: QLatin1String(NM_SETTING_BOND_INTERFACE_NAME))) { |
| 83 | setInterfaceName(setting.value(key: QLatin1String(NM_SETTING_BOND_INTERFACE_NAME)).toString()); |
| 84 | } |
| 85 | |
| 86 | if (setting.contains(key: QLatin1String(NM_SETTING_BOND_OPTIONS))) { |
| 87 | setOptions(qdbus_cast<NMStringMap>(v: setting.value(key: QLatin1String(NM_SETTING_BOND_OPTIONS)))); |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | QVariantMap NetworkManager::BondSetting::toMap() const |
| 92 | { |
| 93 | QVariantMap setting; |
| 94 | if (!interfaceName().isEmpty()) { |
| 95 | setting.insert(key: QLatin1String(NM_SETTING_BOND_INTERFACE_NAME), value: interfaceName()); |
| 96 | } |
| 97 | if (!options().isEmpty()) { |
| 98 | setting.insert(key: QLatin1String(NM_SETTING_BOND_OPTIONS), value: QVariant::fromValue<NMStringMap>(value: options())); |
| 99 | } |
| 100 | |
| 101 | return setting; |
| 102 | } |
| 103 | |
| 104 | QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::BondSetting &setting) |
| 105 | { |
| 106 | dbg.nospace() << "type: "<< setting.typeAsString(type: setting.type()) << '\n'; |
| 107 | dbg.nospace() << "initialized: "<< !setting.isNull() << '\n'; |
| 108 | |
| 109 | dbg.nospace() << NM_SETTING_BOND_INTERFACE_NAME << ": "<< setting.interfaceName() << '\n'; |
| 110 | dbg.nospace() << NM_SETTING_BOND_OPTIONS << ": "<< setting.options() << '\n'; |
| 111 | |
| 112 | return dbg.maybeSpace(); |
| 113 | } |
| 114 |
