File indexing completed on 2024-10-13 09:39:46

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 "bridgedevice_p.h"
0008 #include "manager_p.h"
0009 
0010 NetworkManager::BridgeDevicePrivate::BridgeDevicePrivate(const QString &path, BridgeDevice *q)
0011     : DevicePrivate(path, q)
0012 #ifdef NMQT_STATIC
0013     , iface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::sessionBus())
0014 #else
0015     , iface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::systemBus())
0016 #endif
0017     , carrier(false)
0018 {
0019 }
0020 
0021 NetworkManager::BridgeDevicePrivate::~BridgeDevicePrivate()
0022 {
0023 }
0024 
0025 NetworkManager::BridgeDevice::BridgeDevice(const QString &path, QObject *parent)
0026     : Device(*new BridgeDevicePrivate(path, this), parent)
0027 {
0028     Q_D(BridgeDevice);
0029 
0030     QVariantMap initialProperties = NetworkManagerPrivate::retrieveInitialProperties(d->iface.staticInterfaceName(), path);
0031     if (!initialProperties.isEmpty()) {
0032         d->propertiesChanged(initialProperties);
0033     }
0034 }
0035 
0036 NetworkManager::BridgeDevice::~BridgeDevice()
0037 {
0038 }
0039 
0040 NetworkManager::Device::Type NetworkManager::BridgeDevice::type() const
0041 {
0042     return NetworkManager::Device::Bridge;
0043 }
0044 
0045 bool NetworkManager::BridgeDevice::carrier() const
0046 {
0047     Q_D(const BridgeDevice);
0048 
0049     return d->carrier;
0050 }
0051 
0052 QString NetworkManager::BridgeDevice::hwAddress() const
0053 {
0054     Q_D(const BridgeDevice);
0055 
0056     return d->hwAddress;
0057 }
0058 
0059 QStringList NetworkManager::BridgeDevice::slaves() const
0060 {
0061     Q_D(const BridgeDevice);
0062 
0063     return d->slaves;
0064 }
0065 
0066 void NetworkManager::BridgeDevicePrivate::propertyChanged(const QString &property, const QVariant &value)
0067 {
0068     Q_Q(BridgeDevice);
0069 
0070     if (property == QLatin1String("Carrier")) {
0071         carrier = value.toBool();
0072         Q_EMIT q->carrierChanged(carrier);
0073     } else if (property == QLatin1String("HwAddress")) {
0074         hwAddress = value.toString();
0075         Q_EMIT q->hwAddressChanged(hwAddress);
0076     } else if (property == QLatin1String("Slaves")) {
0077         QStringList list;
0078         const QList<QDBusObjectPath> opList = qdbus_cast<QList<QDBusObjectPath>>(value);
0079         for (const QDBusObjectPath &op : opList) {
0080             list << op.path();
0081         }
0082         slaves = list;
0083         Q_EMIT q->slavesChanged(slaves);
0084     } else {
0085         DevicePrivate::propertyChanged(property, value);
0086     }
0087 }
0088 
0089 #include "moc_bridgedevice.cpp"