File indexing completed on 2024-04-14 14:30:35

0001 /*
0002     SPDX-FileCopyrightText: 2013 Jan Grulich <jgrulich@redhat.com>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 
0007 #include "bonddevice_p.h"
0008 #include "device_p.h"
0009 #include "manager.h"
0010 #include "manager_p.h"
0011 
0012 NetworkManager::BondDevicePrivate::BondDevicePrivate(const QString &path, BondDevice *q)
0013     : DevicePrivate(path, q)
0014 #ifdef NMQT_STATIC
0015     , iface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::sessionBus())
0016 #else
0017     , iface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::systemBus())
0018 #endif
0019     , carrier(false)
0020 {
0021 }
0022 
0023 NetworkManager::BondDevice::~BondDevice()
0024 {
0025 }
0026 
0027 NetworkManager::BondDevice::BondDevice(const QString &path, QObject *parent)
0028     : Device(*new BondDevicePrivate(path, this), parent)
0029 {
0030     Q_D(BondDevice);
0031 
0032     QVariantMap initialProperties = NetworkManagerPrivate::retrieveInitialProperties(d->iface.staticInterfaceName(), path);
0033     if (!initialProperties.isEmpty()) {
0034         d->propertiesChanged(initialProperties);
0035     }
0036 
0037 }
0038 
0039 NetworkManager::BondDevicePrivate::~BondDevicePrivate()
0040 {
0041 }
0042 
0043 NetworkManager::Device::Type NetworkManager::BondDevice::type() const
0044 {
0045     return NetworkManager::Device::Bond;
0046 }
0047 
0048 bool NetworkManager::BondDevice::carrier() const
0049 {
0050     Q_D(const BondDevice);
0051 
0052     return d->carrier;
0053 }
0054 
0055 QString NetworkManager::BondDevice::hwAddress() const
0056 {
0057     Q_D(const BondDevice);
0058 
0059     return d->hwAddress;
0060 }
0061 
0062 QStringList NetworkManager::BondDevice::slaves() const
0063 {
0064     Q_D(const BondDevice);
0065 
0066     return d->slaves;
0067 }
0068 
0069 void NetworkManager::BondDevicePrivate::propertyChanged(const QString &property, const QVariant &value)
0070 {
0071     Q_Q(BondDevice);
0072 
0073     if (property == QLatin1String("Carrier")) {
0074         carrier = value.toBool();
0075         Q_EMIT q->carrierChanged(carrier);
0076     } else if (property == QLatin1String("HwAddress")) {
0077         hwAddress = value.toString();
0078         Q_EMIT q->hwAddressChanged(hwAddress);
0079     } else if (property == QLatin1String("Slaves")) {
0080         QStringList list;
0081         const QList<QDBusObjectPath> opList = qdbus_cast<QList<QDBusObjectPath>>(value);
0082         for (const QDBusObjectPath &op : opList) {
0083             list << op.path();
0084         }
0085         slaves = list;
0086         Q_EMIT q->slavesChanged(slaves);
0087     } else {
0088         DevicePrivate::propertyChanged(property, value);
0089     }
0090 }
0091 
0092 #include "moc_bonddevice.cpp"
0093 #include "moc_bonddevice_p.cpp"