File indexing completed on 2025-03-23 12:49:54
0001 /* 0002 SPDX-FileCopyrightText: 2011 Ilia Kats <ilia-kats@gmx.net> 0003 SPDX-FileCopyrightText: 2013 Daniel Nicoletti <dantti12@gmail.com> 0004 0005 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0006 */ 0007 0008 #include "wimaxdevice.h" 0009 #include "manager_p.h" 0010 #include "wimaxdevice_p.h" 0011 0012 #include "nmdebug.h" 0013 0014 #include <QDBusMetaType> 0015 0016 NetworkManager::WimaxDevicePrivate::WimaxDevicePrivate(const QString &path, WimaxDevice *q) 0017 : DevicePrivate(path, q) 0018 #ifdef NMQT_STATIC 0019 , wimaxIface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::sessionBus()) 0020 #else 0021 , wimaxIface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::systemBus()) 0022 #endif 0023 { 0024 qDBusRegisterMetaType<QList<QDBusObjectPath>>(); 0025 const QList<QDBusObjectPath> nsps = wimaxIface.nsps(); 0026 for (const QDBusObjectPath &op : nsps) { 0027 nspMap.insert(op.path(), NetworkManager::WimaxNsp::Ptr()); 0028 // qCDebug(NMQT) << " " << op.path(); 0029 } 0030 } 0031 0032 NetworkManager::WimaxDevice::WimaxDevice(const QString &path, QObject *parent) 0033 : Device(*new WimaxDevicePrivate(path, this), parent) 0034 { 0035 Q_D(WimaxDevice); 0036 0037 connect(&d->wimaxIface, &OrgFreedesktopNetworkManagerDeviceWiMaxInterface::NspAdded, d, &WimaxDevicePrivate::nspAdded); 0038 connect(&d->wimaxIface, &OrgFreedesktopNetworkManagerDeviceWiMaxInterface::NspRemoved, d, &WimaxDevicePrivate::nspRemoved); 0039 0040 QVariantMap initialProperties = NetworkManagerPrivate::retrieveInitialProperties(d->wimaxIface.staticInterfaceName(), path); 0041 if (!initialProperties.isEmpty()) { 0042 d->propertiesChanged(initialProperties); 0043 } 0044 } 0045 0046 NetworkManager::WimaxDevice::~WimaxDevice() 0047 { 0048 } 0049 0050 NetworkManager::Device::Type NetworkManager::WimaxDevice::type() const 0051 { 0052 return NetworkManager::Device::Wimax; 0053 } 0054 0055 QStringList NetworkManager::WimaxDevice::nsps() const 0056 { 0057 Q_D(const WimaxDevice); 0058 return d->nspMap.keys(); 0059 } 0060 0061 NetworkManager::WimaxNsp::Ptr NetworkManager::WimaxDevice::activeNsp() const 0062 { 0063 Q_D(const WimaxDevice); 0064 return findNsp(d->activeNsp); 0065 } 0066 0067 QString NetworkManager::WimaxDevice::hardwareAddress() const 0068 { 0069 Q_D(const WimaxDevice); 0070 return d->hardwareAddress; 0071 } 0072 0073 QString NetworkManager::WimaxDevice::bsid() const 0074 { 0075 Q_D(const WimaxDevice); 0076 return d->bsid; 0077 } 0078 0079 uint NetworkManager::WimaxDevice::centerFrequency() const 0080 { 0081 Q_D(const WimaxDevice); 0082 return d->centerFrequency; 0083 } 0084 0085 int NetworkManager::WimaxDevice::cinr() const 0086 { 0087 Q_D(const WimaxDevice); 0088 return d->cinr; 0089 } 0090 0091 int NetworkManager::WimaxDevice::rssi() const 0092 { 0093 Q_D(const WimaxDevice); 0094 return d->rssi; 0095 } 0096 0097 int NetworkManager::WimaxDevice::txPower() const 0098 { 0099 Q_D(const WimaxDevice); 0100 return d->txPower; 0101 } 0102 0103 NetworkManager::WimaxNsp::Ptr NetworkManager::WimaxDevice::findNsp(const QString &uni) const 0104 { 0105 Q_D(const WimaxDevice); 0106 NetworkManager::WimaxNsp::Ptr nsp; 0107 QMap<QString, NetworkManager::WimaxNsp::Ptr>::ConstIterator mapIt = d->nspMap.constFind(uni); 0108 if (mapIt != d->nspMap.constEnd() && !mapIt.value().isNull()) { 0109 nsp = mapIt.value(); 0110 } else { 0111 nsp = NetworkManager::WimaxNsp::Ptr(new NetworkManager::WimaxNsp(uni), &QObject::deleteLater); 0112 d->nspMap.insert(uni, nsp); 0113 } 0114 0115 return nsp; 0116 } 0117 0118 void NetworkManager::WimaxDevicePrivate::nspAdded(const QDBusObjectPath &nspPath) 0119 { 0120 // qCDebug(NMQT) << nspPath.path(); 0121 Q_Q(WimaxDevice); 0122 if (!nspMap.contains(nspPath.path())) { 0123 nspMap.insert(nspPath.path(), NetworkManager::WimaxNsp::Ptr()); 0124 Q_EMIT q->nspAppeared(nspPath.path()); 0125 } 0126 } 0127 0128 void NetworkManager::WimaxDevicePrivate::nspRemoved(const QDBusObjectPath &nspPath) 0129 { 0130 // qCDebug(NMQT) << nspPath.path(); 0131 Q_Q(WimaxDevice); 0132 if (!nspMap.contains(nspPath.path())) { 0133 qCDebug(NMQT) << "Access point list lookup failed for " << nspPath.path(); 0134 } 0135 Q_EMIT q->nspDisappeared(nspPath.path()); 0136 nspMap.remove(nspPath.path()); 0137 } 0138 0139 void NetworkManager::WimaxDevicePrivate::propertyChanged(const QString &property, const QVariant &value) 0140 { 0141 Q_Q(WimaxDevice); 0142 0143 if (property == QLatin1String("ActiveNsp")) { 0144 activeNsp = qdbus_cast<QDBusObjectPath>(value).path(); 0145 Q_EMIT q->activeNspChanged(activeNsp); 0146 } else if (property == QLatin1String("HwAddress")) { 0147 hardwareAddress = value.toString(); 0148 Q_EMIT q->hardwareAddressChanged(hardwareAddress); 0149 } else if (property == QLatin1String("Bsid")) { 0150 bsid = value.toString(); 0151 Q_EMIT q->bsidChanged(bsid); 0152 } else if (property == QLatin1String("CenterFrequency")) { 0153 centerFrequency = value.toUInt(); 0154 Q_EMIT q->centerFrequencyChanged(centerFrequency); 0155 } else if (property == QLatin1String("Cinr")) { 0156 cinr = value.toInt(); 0157 Q_EMIT q->cinrChanged(cinr); 0158 } else if (property == QLatin1String("Rssi")) { 0159 rssi = value.toInt(); 0160 Q_EMIT q->rssiChanged(rssi); 0161 } else if (property == QLatin1String("TxPower")) { 0162 txPower = value.toInt(); 0163 Q_EMIT q->txPowerChanged(txPower); 0164 } else { 0165 DevicePrivate::propertyChanged(property, value); 0166 } 0167 } 0168 0169 #include "moc_wimaxdevice.cpp" 0170 #include "moc_wimaxdevice_p.cpp"