Add IP address information
This commit is contained in:
parent
b62cad60b2
commit
4a6df2b93c
5
debian/changelog
vendored
5
debian/changelog
vendored
@ -1,3 +1,8 @@
|
||||
libnymea-networkmanager (0.4.0) UNRELEASED; urgency=medium
|
||||
|
||||
|
||||
-- Michael Zanetti <michael.zanetti@guh.io> Mon, 27 Apr 2020 10:24:32 +0200
|
||||
|
||||
libnymea-networkmanager (0.3.0) xenial; urgency=medium
|
||||
[ Michael Zanetti ]
|
||||
* Remove misleading return value, now that the method is async
|
||||
|
||||
@ -385,7 +385,15 @@ void WirelessService::commandGetCurrentConnection(const QVariantMap &request)
|
||||
connectionDataMap.insert("p", 0);
|
||||
connectionDataMap.insert("i", "");
|
||||
} else {
|
||||
QHostAddress address = wifiInterface.addressEntries().first().ip();
|
||||
QHostAddress address;
|
||||
// Note: for now, we'll just use the first IPv4 address. However, in a future version
|
||||
// this should somehow pack all addresses, IPv4 and IPv6 ones.
|
||||
foreach (const QNetworkAddressEntry &entry, wifiInterface.addressEntries()) {
|
||||
if (entry.ip().protocol() == QAbstractSocket::IPv4Protocol) {
|
||||
address = entry.ip();
|
||||
break;
|
||||
}
|
||||
}
|
||||
qCDebug(dcNetworkManagerBluetoothServer()) << "Current connection:" << m_device->activeAccessPoint() << address.toString();
|
||||
connectionDataMap.insert("e", m_device->activeAccessPoint()->ssid());
|
||||
connectionDataMap.insert("m", m_device->activeAccessPoint()->macAddress());
|
||||
|
||||
@ -170,6 +170,8 @@ NetworkDevice::NetworkDevice(const QDBusObjectPath &objectPath, QObject *parent)
|
||||
return;
|
||||
}
|
||||
|
||||
QDBusConnection::systemBus().connect(NetworkManagerUtils::networkManagerServiceString(), m_objectPath.path(), NetworkManagerUtils::deviceInterfaceString(), "StateChanged", this, SLOT(onStateChanged(uint,uint,uint)));
|
||||
|
||||
m_udi = m_networkDeviceInterface->property("Udi").toString();
|
||||
m_interface = m_networkDeviceInterface->property("Interface").toString();
|
||||
m_ipInterface = m_networkDeviceInterface->property("IpInterface").toString();
|
||||
@ -185,10 +187,8 @@ NetworkDevice::NetworkDevice(const QDBusObjectPath &objectPath, QObject *parent)
|
||||
m_deviceType = NetworkDeviceType(m_networkDeviceInterface->property("DeviceType").toUInt());
|
||||
|
||||
m_activeConnection = qdbus_cast<QDBusObjectPath>(m_networkDeviceInterface->property("ActiveConnection"));
|
||||
m_ip4Config = qdbus_cast<QDBusObjectPath>(m_networkDeviceInterface->property("Ip4Config"));
|
||||
m_ip6Config = qdbus_cast<QDBusObjectPath>(m_networkDeviceInterface->property("Ip6Config"));
|
||||
|
||||
QDBusConnection::systemBus().connect(NetworkManagerUtils::networkManagerServiceString(), m_objectPath.path(), NetworkManagerUtils::deviceInterfaceString(), "StateChanged", this, SLOT(onStateChanged(uint,uint,uint)));
|
||||
m_ipv4Addresses = readIpAddresses("Ip4Config", "org.freedesktop.NetworkManager.IP4Config");
|
||||
m_ipv6Addresses = readIpAddresses("Ip6Config", "org.freedesktop.NetworkManager.IP6Config");
|
||||
}
|
||||
|
||||
/*! Returns the dbus object path of this \l{NetworkDevice}. */
|
||||
@ -257,6 +257,18 @@ bool NetworkDevice::autoconnect() const
|
||||
return m_autoconnect;
|
||||
}
|
||||
|
||||
/*! Returns IPv4 addresses for this \l{NetworkDevice}. */
|
||||
QStringList NetworkDevice::ipv4Addresses() const
|
||||
{
|
||||
return m_ipv4Addresses;
|
||||
}
|
||||
|
||||
/*! Returns IPv4 addresses for this \l{NetworkDevice}. */
|
||||
QStringList NetworkDevice::ipv6Addresses() const
|
||||
{
|
||||
return m_ipv6Addresses;
|
||||
}
|
||||
|
||||
/*! Returns the device state of this \l{NetworkDevice}. \sa NetworkDeviceState, */
|
||||
NetworkDevice::NetworkDeviceState NetworkDevice::deviceState() const
|
||||
{
|
||||
@ -287,12 +299,6 @@ QDBusObjectPath NetworkDevice::activeConnection() const
|
||||
return m_activeConnection;
|
||||
}
|
||||
|
||||
/*! Returns the dbus object path from the IPv4 configuration of this \l{NetworkDevice}. */
|
||||
QDBusObjectPath NetworkDevice::ip4Config() const
|
||||
{
|
||||
return m_ip4Config;
|
||||
}
|
||||
|
||||
/*! Returns the list of dbus object paths for the currently available connection of this \l{NetworkDevice}. */
|
||||
QList<QDBusObjectPath> NetworkDevice::availableConnections() const
|
||||
{
|
||||
@ -335,15 +341,44 @@ QString NetworkDevice::deviceStateReasonToString(const NetworkDevice::NetworkDev
|
||||
return QString(metaEnum.valueToKey(deviceStateReason));
|
||||
}
|
||||
|
||||
QStringList NetworkDevice::readIpAddresses(const QString &property, const QString &interface)
|
||||
{
|
||||
QStringList ret;
|
||||
QDBusObjectPath configPath = qdbus_cast<QDBusObjectPath>(m_networkDeviceInterface->property(property.toUtf8()));
|
||||
|
||||
if (configPath.path() != "/") {
|
||||
QDBusInterface iface(NetworkManagerUtils::networkManagerServiceString(), configPath.path(), "org.freedesktop.DBus.Properties", QDBusConnection::systemBus());
|
||||
|
||||
QDBusMessage reply = iface.call("Get", interface, "AddressData");
|
||||
QVariant v = reply.arguments().first();
|
||||
QDBusArgument arg = v.value<QDBusVariant>().variant().value<QDBusArgument>();
|
||||
|
||||
arg.beginArray();
|
||||
while(!arg.atEnd()) {
|
||||
QVariantMap m;
|
||||
arg >> m;
|
||||
ret.append(m.value("address").toString());
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void NetworkDevice::onStateChanged(uint newState, uint oldState, uint reason)
|
||||
{
|
||||
Q_UNUSED(oldState)
|
||||
qCDebug(dcNetworkManager()) << m_interface << "--> State changed:" << deviceStateToString(NetworkDeviceState(newState)) << ":" << deviceStateReasonToString(NetworkDeviceStateReason(reason));
|
||||
|
||||
|
||||
if (m_deviceState != NetworkDeviceState(newState)) {
|
||||
m_deviceState = NetworkDeviceState(newState);
|
||||
m_ipv4Addresses = readIpAddresses("Ip4Config", "org.freedesktop.NetworkManager.IP4Config");
|
||||
m_ipv6Addresses = readIpAddresses("Ip6Config", "org.freedesktop.NetworkManager.IP6Config");
|
||||
qCDebug(dcNetworkManager()) << "Fooooooooooooo" << m_ipv4Addresses << m_ipv6Addresses;
|
||||
emit deviceChanged();
|
||||
|
||||
m_deviceState = NetworkDeviceState(newState);
|
||||
emit stateChanged(m_deviceState);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
QDebug operator<<(QDebug debug, NetworkDevice *device)
|
||||
|
||||
@ -170,6 +170,8 @@ public:
|
||||
uint mtu() const;
|
||||
uint metered() const;
|
||||
bool autoconnect() const;
|
||||
QStringList ipv4Addresses() const;
|
||||
QStringList ipv6Addresses() const;
|
||||
|
||||
NetworkDeviceState deviceState() const;
|
||||
QString deviceStateString() const;
|
||||
@ -200,6 +202,8 @@ private:
|
||||
QString m_driverVersion;
|
||||
QString m_firmwareVersion;
|
||||
QString m_physicalPortId;
|
||||
QList<QString> m_ipv4Addresses;
|
||||
QList<QString> m_ipv6Addresses;
|
||||
uint m_mtu = 0;
|
||||
uint m_metered = 0;
|
||||
bool m_autoconnect = false;
|
||||
@ -208,11 +212,12 @@ private:
|
||||
NetworkDeviceType m_deviceType = NetworkDeviceTypeUnknown;
|
||||
|
||||
QDBusObjectPath m_activeConnection;
|
||||
QDBusObjectPath m_ip4Config;
|
||||
QDBusObjectPath m_ip6Config;
|
||||
|
||||
QList<QDBusObjectPath> m_availableConnections;
|
||||
|
||||
private:
|
||||
QStringList readIpAddresses(const QString &property, const QString &interface);
|
||||
|
||||
private slots:
|
||||
void onStateChanged(uint newState, uint oldState, uint reason);
|
||||
|
||||
|
||||
@ -355,7 +355,7 @@ void NetworkManager::init()
|
||||
qCDebug(dcNetworkManager()) << "Initializing network manager";
|
||||
// Check DBus connection
|
||||
if (!QDBusConnection::systemBus().isConnected()) {
|
||||
qCWarning(dcNetworkManager()) << "System DBus not connected. NetworkManagre not available.";
|
||||
qCWarning(dcNetworkManager()) << "System DBus not connected. NetworkManager not available.";
|
||||
setAvailable(false);
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user