| 1 | /* |
| 2 | SPDX-FileCopyrightText: 2011 Ilia Kats <ilia-kats@gmx.net> |
| 3 | SPDX-FileCopyrightText: 2013 Daniel Nicoletti <dantti12@gmail.com> |
| 4 | |
| 5 | SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL |
| 6 | */ |
| 7 | |
| 8 | #include "wimaxdevice.h" |
| 9 | #include "manager_p.h" |
| 10 | #include "wimaxdevice_p.h" |
| 11 | |
| 12 | #include "nmdebug.h" |
| 13 | |
| 14 | #include <QDBusMetaType> |
| 15 | |
| 16 | NetworkManager::WimaxDevicePrivate::WimaxDevicePrivate(const QString &path, WimaxDevice *q) |
| 17 | : DevicePrivate(path, q) |
| 18 | #ifdef NMQT_STATIC |
| 19 | , wimaxIface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::sessionBus()) |
| 20 | #else |
| 21 | , wimaxIface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::systemBus()) |
| 22 | #endif |
| 23 | { |
| 24 | qDBusRegisterMetaType<QList<QDBusObjectPath>>(); |
| 25 | const QList<QDBusObjectPath> nsps = wimaxIface.nsps(); |
| 26 | for (const QDBusObjectPath &op : nsps) { |
| 27 | nspMap.insert(key: op.path(), value: NetworkManager::WimaxNsp::Ptr()); |
| 28 | // qCDebug(NMQT) << " " << op.path(); |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | NetworkManager::WimaxDevice::WimaxDevice(const QString &path, QObject *parent) |
| 33 | : Device(*new WimaxDevicePrivate(path, this), parent) |
| 34 | { |
| 35 | Q_D(WimaxDevice); |
| 36 | |
| 37 | connect(sender: &d->wimaxIface, signal: &OrgFreedesktopNetworkManagerDeviceWiMaxInterface::NspAdded, context: d, slot: &WimaxDevicePrivate::nspAdded); |
| 38 | connect(sender: &d->wimaxIface, signal: &OrgFreedesktopNetworkManagerDeviceWiMaxInterface::NspRemoved, context: d, slot: &WimaxDevicePrivate::nspRemoved); |
| 39 | |
| 40 | QVariantMap initialProperties = NetworkManagerPrivate::retrieveInitialProperties(interfaceName: d->wimaxIface.staticInterfaceName(), path); |
| 41 | if (!initialProperties.isEmpty()) { |
| 42 | d->propertiesChanged(properties: initialProperties); |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | NetworkManager::WimaxDevice::~WimaxDevice() |
| 47 | { |
| 48 | } |
| 49 | |
| 50 | NetworkManager::Device::Type NetworkManager::WimaxDevice::type() const |
| 51 | { |
| 52 | return NetworkManager::Device::Wimax; |
| 53 | } |
| 54 | |
| 55 | QStringList NetworkManager::WimaxDevice::nsps() const |
| 56 | { |
| 57 | Q_D(const WimaxDevice); |
| 58 | return d->nspMap.keys(); |
| 59 | } |
| 60 | |
| 61 | NetworkManager::WimaxNsp::Ptr NetworkManager::WimaxDevice::activeNsp() const |
| 62 | { |
| 63 | Q_D(const WimaxDevice); |
| 64 | return findNsp(uni: d->activeNsp); |
| 65 | } |
| 66 | |
| 67 | QString NetworkManager::WimaxDevice::hardwareAddress() const |
| 68 | { |
| 69 | Q_D(const WimaxDevice); |
| 70 | return d->hardwareAddress; |
| 71 | } |
| 72 | |
| 73 | QString NetworkManager::WimaxDevice::bsid() const |
| 74 | { |
| 75 | Q_D(const WimaxDevice); |
| 76 | return d->bsid; |
| 77 | } |
| 78 | |
| 79 | uint NetworkManager::WimaxDevice::centerFrequency() const |
| 80 | { |
| 81 | Q_D(const WimaxDevice); |
| 82 | return d->centerFrequency; |
| 83 | } |
| 84 | |
| 85 | int NetworkManager::WimaxDevice::cinr() const |
| 86 | { |
| 87 | Q_D(const WimaxDevice); |
| 88 | return d->cinr; |
| 89 | } |
| 90 | |
| 91 | int NetworkManager::WimaxDevice::() const |
| 92 | { |
| 93 | Q_D(const WimaxDevice); |
| 94 | return d->rssi; |
| 95 | } |
| 96 | |
| 97 | int NetworkManager::WimaxDevice::txPower() const |
| 98 | { |
| 99 | Q_D(const WimaxDevice); |
| 100 | return d->txPower; |
| 101 | } |
| 102 | |
| 103 | NetworkManager::WimaxNsp::Ptr NetworkManager::WimaxDevice::findNsp(const QString &uni) const |
| 104 | { |
| 105 | Q_D(const WimaxDevice); |
| 106 | NetworkManager::WimaxNsp::Ptr nsp; |
| 107 | QMap<QString, NetworkManager::WimaxNsp::Ptr>::ConstIterator mapIt = d->nspMap.constFind(key: uni); |
| 108 | if (mapIt != d->nspMap.constEnd() && !mapIt.value().isNull()) { |
| 109 | nsp = mapIt.value(); |
| 110 | } else { |
| 111 | nsp = NetworkManager::WimaxNsp::Ptr(new NetworkManager::WimaxNsp(uni), &QObject::deleteLater); |
| 112 | d->nspMap.insert(key: uni, value: nsp); |
| 113 | } |
| 114 | |
| 115 | return nsp; |
| 116 | } |
| 117 | |
| 118 | void NetworkManager::WimaxDevicePrivate::nspAdded(const QDBusObjectPath &nspPath) |
| 119 | { |
| 120 | // qCDebug(NMQT) << nspPath.path(); |
| 121 | Q_Q(WimaxDevice); |
| 122 | if (!nspMap.contains(key: nspPath.path())) { |
| 123 | nspMap.insert(key: nspPath.path(), value: NetworkManager::WimaxNsp::Ptr()); |
| 124 | Q_EMIT q->nspAppeared(nspPath.path()); |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | void NetworkManager::WimaxDevicePrivate::nspRemoved(const QDBusObjectPath &nspPath) |
| 129 | { |
| 130 | // qCDebug(NMQT) << nspPath.path(); |
| 131 | Q_Q(WimaxDevice); |
| 132 | if (!nspMap.contains(key: nspPath.path())) { |
| 133 | qCDebug(NMQT) << "Access point list lookup failed for " << nspPath.path(); |
| 134 | } |
| 135 | Q_EMIT q->nspDisappeared(nspPath.path()); |
| 136 | nspMap.remove(key: nspPath.path()); |
| 137 | } |
| 138 | |
| 139 | void NetworkManager::WimaxDevicePrivate::propertyChanged(const QString &property, const QVariant &value) |
| 140 | { |
| 141 | Q_Q(WimaxDevice); |
| 142 | |
| 143 | if (property == QLatin1String("ActiveNsp" )) { |
| 144 | activeNsp = qdbus_cast<QDBusObjectPath>(v: value).path(); |
| 145 | Q_EMIT q->activeNspChanged(activeNsp); |
| 146 | } else if (property == QLatin1String("HwAddress" )) { |
| 147 | hardwareAddress = value.toString(); |
| 148 | Q_EMIT q->hardwareAddressChanged(hardwareAddress); |
| 149 | } else if (property == QLatin1String("Bsid" )) { |
| 150 | bsid = value.toString(); |
| 151 | Q_EMIT q->bsidChanged(bsid); |
| 152 | } else if (property == QLatin1String("CenterFrequency" )) { |
| 153 | centerFrequency = value.toUInt(); |
| 154 | Q_EMIT q->centerFrequencyChanged(centerFrequency); |
| 155 | } else if (property == QLatin1String("Cinr" )) { |
| 156 | cinr = value.toInt(); |
| 157 | Q_EMIT q->cinrChanged(cinr); |
| 158 | } else if (property == QLatin1String("Rssi" )) { |
| 159 | rssi = value.toInt(); |
| 160 | Q_EMIT q->rssiChanged(rssi); |
| 161 | } else if (property == QLatin1String("TxPower" )) { |
| 162 | txPower = value.toInt(); |
| 163 | Q_EMIT q->txPowerChanged(txPower); |
| 164 | } else { |
| 165 | DevicePrivate::propertyChanged(property, value); |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | #include "moc_wimaxdevice.cpp" |
| 170 | #include "moc_wimaxdevice_p.cpp" |
| 171 | |