Use a property cache to cut down on blocking calls

Refactor old code
Stop memory leaks
Properly support mobile data (ofono)

Change-Id: I7f23882ee0ee345a049a4a93ddd452b6d2e53710
Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
This commit is contained in:
Lorn Potter 2014-10-29 19:40:43 +10:00
parent af279b34a8
commit 4763a3571f
11 changed files with 855 additions and 668 deletions

View File

@ -8,14 +8,14 @@ QT = core network-private dbus
CONFIG += link_pkgconfig
HEADERS += qconnmanservice_linux_p.h \
qofonoservice_linux_p.h \
../linux_common/qofonoservice_linux_p.h \
qconnmanengine.h \
../qnetworksession_impl.h \
../qbearerengine_impl.h
SOURCES += main.cpp \
qconnmanservice_linux.cpp \
qofonoservice_linux.cpp \
../linux_common/qofonoservice_linux.cpp \
qconnmanengine.cpp \
../qnetworksession_impl.cpp

View File

@ -48,7 +48,7 @@
#include "../qbearerengine_impl.h"
#include "qconnmanservice_linux_p.h"
#include "qofonoservice_linux_p.h"
#include "../linux_common/qofonoservice_linux_p.h"
#include <QMap>
#include <QVariant>

View File

@ -95,14 +95,12 @@ QStringList QOfonoManagerInterface::getModems()
{
if (modemList.isEmpty()) {
QList<QVariant> argumentList;
QDBusPendingReply<PathPropertiesList> reply = asyncCallWithArgumentList(QLatin1String("GetModems"), argumentList);
QDBusPendingReply<PathPropertiesList> reply = callWithArgumentList(QDBus::Block, QLatin1String("GetModems"), argumentList);
reply.waitForFinished();
if (!reply.isError()) {
foreach (ObjectPathProperties modem, reply.value()) {
modemList << modem.path.path();
}
} else {
qDebug() << reply.error().message();
}
}
@ -175,7 +173,7 @@ QVariantMap QOfonoModemInterface::getProperties()
{
if (propertiesMap.isEmpty()) {
QList<QVariant> argumentList;
QDBusPendingReply<QVariantMap> reply = asyncCallWithArgumentList(QLatin1String("GetProperties"), argumentList);
QDBusPendingReply<QVariantMap> reply = callWithArgumentList(QDBus::Block, QLatin1String("GetProperties"), argumentList);
if (!reply.isError()) {
propertiesMap = reply.value();
}
@ -187,6 +185,7 @@ QVariant QOfonoModemInterface::getProperty(const QString &property)
{
QVariant var;
QVariantMap map = getProperties();
if (map.contains(property))
var = map.value(property);
return var;
}
@ -214,6 +213,7 @@ QVariant QOfonoNetworkRegistrationInterface::getProperty(const QString &property
{
QVariant var;
QVariantMap map = getProperties();
if (map.contains(property))
var = map.value(property);
return var;
}
@ -222,12 +222,10 @@ QVariantMap QOfonoNetworkRegistrationInterface::getProperties()
{
if (propertiesMap.isEmpty()) {
QList<QVariant> argumentList;
QDBusPendingReply<QVariantMap> reply = asyncCallWithArgumentList(QLatin1String("GetProperties"), argumentList);
QDBusPendingReply<QVariantMap> reply = callWithArgumentList(QDBus::Block, QLatin1String("GetProperties"), argumentList);
reply.waitForFinished();
if (!reply.isError()) {
propertiesMap = reply.value();
} else {
qDebug() << reply.error().message();
}
}
return propertiesMap;
@ -270,10 +268,17 @@ bool QOfonoDataConnectionManagerInterface::roamingAllowed()
return qdbus_cast<bool>(var);
}
QString QOfonoDataConnectionManagerInterface::bearer()
{
QVariant var = getProperty(QStringLiteral("Bearer"));
return qdbus_cast<QString>(var);
}
QVariant QOfonoDataConnectionManagerInterface::getProperty(const QString &property)
{
QVariant var;
QVariantMap map = getProperties();
if (map.contains(property))
var = map.value(property);
return var;
}
@ -282,7 +287,7 @@ QVariantMap QOfonoDataConnectionManagerInterface::getProperties()
{
if (propertiesMap.isEmpty()) {
QList<QVariant> argumentList;
QDBusPendingReply<QVariantMap> reply = asyncCallWithArgumentList(QLatin1String("GetProperties"), argumentList);
QDBusPendingReply<QVariantMap> reply = callWithArgumentList(QDBus::Block, QLatin1String("GetProperties"), argumentList);
if (!reply.isError()) {
propertiesMap = reply.value();
}
@ -297,6 +302,68 @@ void QOfonoDataConnectionManagerInterface::propertyChanged(const QString &name,
Q_EMIT roamingAllowedChanged(value.variant().toBool());
}
QOfonoConnectionContextInterface::QOfonoConnectionContextInterface(const QString &dbusPathName, QObject *parent)
: QDBusAbstractInterface(QLatin1String(OFONO_SERVICE),
dbusPathName,
OFONO_CONNECTION_CONTEXT_INTERFACE,
QDBusConnection::systemBus(), parent)
{
QDBusConnection::systemBus().connect(QLatin1String(OFONO_SERVICE),
path(),
QLatin1String(OFONO_MODEM_INTERFACE),
QLatin1String("PropertyChanged"),
this,SLOT(propertyChanged(QString,QDBusVariant)));
}
QOfonoConnectionContextInterface::~QOfonoConnectionContextInterface()
{
}
QVariantMap QOfonoConnectionContextInterface::getProperties()
{
if (propertiesMap.isEmpty()) {
QList<QVariant> argumentList;
QDBusPendingReply<QVariantMap> reply = callWithArgumentList(QDBus::Block, QLatin1String("GetProperties"), argumentList);
if (!reply.isError()) {
propertiesMap = reply.value();
}
}
return propertiesMap;
}
void QOfonoConnectionContextInterface::propertyChanged(const QString &name, const QDBusVariant &value)
{
propertiesMap[name] = value.variant();
}
QVariant QOfonoConnectionContextInterface::getProperty(const QString &property)
{
QVariant var;
QVariantMap map = getProperties();
if (map.contains(property))
var = map.value(property);
return var;
}
bool QOfonoConnectionContextInterface::active()
{
QVariant var = getProperty(QStringLiteral("Active"));
return qdbus_cast<bool>(var);
}
QString QOfonoConnectionContextInterface::accessPointName()
{
QVariant var = getProperty(QStringLiteral("AccessPointName"));
return qdbus_cast<QString>(var);
}
QString QOfonoConnectionContextInterface::name()
{
QVariant var = getProperty(QStringLiteral("Name"));
return qdbus_cast<QString>(var);
}
QT_END_NAMESPACE
#endif // QT_NO_DBUS

View File

@ -67,6 +67,7 @@
#define OFONO_MODEM_INTERFACE "org.ofono.Modem"
#define OFONO_NETWORK_REGISTRATION_INTERFACE "org.ofono.NetworkRegistration"
#define OFONO_DATA_CONNECTION_MANAGER_INTERFACE "org.ofono.ConnectionManager"
#define OFONO_CONNECTION_CONTEXT_INTERFACE "org.ofono.ConnectionContext"
QT_BEGIN_NAMESPACE
@ -152,17 +153,39 @@ public:
QStringList contexts();
bool roamingAllowed();
QVariant getProperty(const QString &);
QString bearer();
Q_SIGNALS:
void roamingAllowedChanged(bool);
private:
QVariantMap getProperties();
QVariantMap propertiesMap;
QVariant getProperty(const QString &);
QStringList contextList;
private slots:
void propertyChanged(const QString &, const QDBusVariant &value);
};
class QOfonoConnectionContextInterface : public QDBusAbstractInterface
{
Q_OBJECT
public:
explicit QOfonoConnectionContextInterface(const QString &dbusPathName, QObject *parent = 0);
~QOfonoConnectionContextInterface();
QVariant getProperty(const QString &);
bool active();
QString accessPointName();
QString name();
Q_SIGNALS:
private:
QVariantMap getProperties();
QVariantMap propertiesMap;
private slots:
void propertyChanged(const QString &, const QDBusVariant &value);
};
QT_END_NAMESPACE

View File

@ -6,16 +6,16 @@ load(qt_plugin)
QT = core network-private dbus
HEADERS += qnmdbushelper.h \
qnetworkmanagerservice.h \
HEADERS += qnetworkmanagerservice.h \
qnetworkmanagerengine.h \
../linux_common/qofonoservice_linux_p.h \
../qnetworksession_impl.h \
../qbearerengine_impl.h
SOURCES += main.cpp \
qnmdbushelper.cpp \
qnetworkmanagerservice.cpp \
qnetworkmanagerengine.cpp \
../linux_common/qofonoservice_linux.cpp \
../qnetworksession_impl.cpp
OTHER_FILES += networkmanager.json

View File

@ -47,6 +47,7 @@
#include <QDBusInterface>
#include <QDBusMessage>
#include <QDBusReply>
#include "../linux_common/qofonoservice_linux_p.h"
#ifndef QT_NO_BEARERMANAGEMENT
#ifndef QT_NO_DBUS
@ -57,44 +58,55 @@ QNetworkManagerEngine::QNetworkManagerEngine(QObject *parent)
: QBearerEngineImpl(parent),
managerInterface(new QNetworkManagerInterface(this)),
systemSettings(new QNetworkManagerSettings(NM_DBUS_SERVICE, this)),
userSettings(new QNetworkManagerSettings(NM_DBUS_SERVICE, this))
ofonoManager(new QOfonoManagerInterface(this)),
ofonoNetwork(0),
ofonoContextManager(0)
{
if (!managerInterface->isValid())
return;
managerInterface->setConnections();
qDBusRegisterMetaType<QNmSettingsMap>();
connect(managerInterface, SIGNAL(deviceAdded(QDBusObjectPath)),
this, SLOT(deviceAdded(QDBusObjectPath)));
connect(managerInterface, SIGNAL(deviceRemoved(QDBusObjectPath)),
this, SLOT(deviceRemoved(QDBusObjectPath)));
connect(managerInterface, SIGNAL(activationFinished(QDBusPendingCallWatcher*)),
this, SLOT(activationFinished(QDBusPendingCallWatcher*)));
connect(managerInterface, SIGNAL(propertiesChanged(QString,QMap<QString,QVariant>)),
this, SLOT(interfacePropertiesChanged(QString,QMap<QString,QVariant>)));
connect(managerInterface, SIGNAL(propertiesChanged(QMap<QString,QVariant>)),
this, SLOT(interfacePropertiesChanged(QMap<QString,QVariant>)));
managerInterface->setConnections();
qDBusRegisterMetaType<QNmSettingsMap>();
systemSettings->setConnections();
connect(systemSettings, SIGNAL(newConnection(QDBusObjectPath)),
this, SLOT(newConnection(QDBusObjectPath)));
userSettings->setConnections();
connect(userSettings, SIGNAL(newConnection(QDBusObjectPath)),
this, SLOT(newConnection(QDBusObjectPath)));
systemSettings->setConnections();
}
QNetworkManagerEngine::~QNetworkManagerEngine()
{
qDeleteAll(connections);
connections.clear();
qDeleteAll(accessPoints);
accessPoints.clear();
qDeleteAll(wirelessDevices);
qDeleteAll(activeConnections);
wirelessDevices.clear();
qDeleteAll(activeConnectionsList);
activeConnectionsList.clear();
qDeleteAll(interfaceDevices);
interfaceDevices.clear();
connectionInterfaces.clear();
}
void QNetworkManagerEngine::initialize()
{
QMutexLocker locker(&mutex);
connect(ofonoManager,SIGNAL(modemChanged()),this,SLOT(changedModem()));
ofonoNetwork = new QOfonoNetworkRegistrationInterface(ofonoManager->currentModem(),this);
ofonoContextManager = new QOfonoDataConnectionManagerInterface(ofonoManager->currentModem(),this);
// Get current list of access points.
foreach (const QDBusObjectPath &devicePath, managerInterface->getDevices()) {
locker.unlock();
@ -102,8 +114,24 @@ void QNetworkManagerEngine::initialize()
locker.relock();
}
// Get connections.
// Get active connections.
foreach (const QDBusObjectPath &acPath, managerInterface->activeConnections()) {
QNetworkManagerConnectionActive *activeConnection =
new QNetworkManagerConnectionActive(acPath.path(),this);
activeConnectionsList.insert(acPath.path(), activeConnection);
connect(activeConnection, SIGNAL(propertiesChanged(QMap<QString,QVariant>)),
this, SLOT(activeConnectionPropertiesChanged(QMap<QString,QVariant>)));
activeConnection->setConnections();
QList<QDBusObjectPath> devices = activeConnection->devices();
if (!devices.isEmpty()) {
QNetworkManagerInterfaceDevice device(devices.at(0).path(),this);
connectionInterfaces.insert(activeConnection->connection().path(),device.networkInterface());
}
}
// Get connections.
foreach (const QDBusObjectPath &settingsPath, systemSettings->listConnections()) {
locker.unlock();
if (!hasIdentifier(settingsPath.path()))
@ -111,56 +139,18 @@ void QNetworkManagerEngine::initialize()
locker.relock();
}
foreach (const QDBusObjectPath &settingsPath, userSettings->listConnections()) {
locker.unlock();
if (!hasIdentifier(settingsPath.path()))
newConnection(settingsPath, userSettings);
locker.relock();
}
// Get active connections.
foreach (const QDBusObjectPath &acPath, managerInterface->activeConnections()) {
QNetworkManagerConnectionActive *activeConnection =
new QNetworkManagerConnectionActive(acPath.path(),this);
activeConnections.insert(acPath.path(), activeConnection);
activeConnection->setConnections();
connect(activeConnection, SIGNAL(propertiesChanged(QString,QMap<QString,QVariant>)),
this, SLOT(activeConnectionPropertiesChanged(QString,QMap<QString,QVariant>)));
}
Q_EMIT updateCompleted();
}
bool QNetworkManagerEngine::networkManagerAvailable() const
{
QMutexLocker locker(&mutex);
return managerInterface->isValid();
}
QString QNetworkManagerEngine::getInterfaceFromId(const QString &id)
QString QNetworkManagerEngine::getInterfaceFromId(const QString &settingsPath)
{
QMutexLocker locker(&mutex);
foreach (const QDBusObjectPath &acPath, managerInterface->activeConnections()) {
QNetworkManagerConnectionActive activeConnection(acPath.path());
const QString identifier = activeConnection.connection().path();
if (id == identifier) {
QList<QDBusObjectPath> devices = activeConnection.devices();
if (devices.isEmpty())
continue;
QNetworkManagerInterfaceDevice device(devices.at(0).path());
return device.networkInterface();
return connectionInterfaces.value(settingsPath);
}
}
return QString();
}
bool QNetworkManagerEngine::hasIdentifier(const QString &id)
{
@ -177,35 +167,34 @@ void QNetworkManagerEngine::connectToId(const QString &id)
if (!connection)
return;
QNmSettingsMap map = connection->getSettings();
const QString connectionType = map.value("connection").value("type").toString();
NMDeviceType connectionType = connection->getType();
QString dbusDevicePath;
foreach (const QDBusObjectPath &devicePath, managerInterface->getDevices()) {
QNetworkManagerInterfaceDevice device(devicePath.path());
if (device.deviceType() == DEVICE_TYPE_ETHERNET &&
connectionType == QLatin1String("802-3-ethernet")) {
dbusDevicePath = devicePath.path();
break;
} else if (device.deviceType() == DEVICE_TYPE_WIFI &&
connectionType == QLatin1String("802-11-wireless")) {
dbusDevicePath = devicePath.path();
break;
} else if (device.deviceType() == DEVICE_TYPE_MODEM &&
connectionType == QLatin1String("gsm")) {
dbusDevicePath = devicePath.path();
break;
}
}
const QString service = connection->connectionInterface()->service();
const QString settingsPath = connection->connectionInterface()->path();
QString specificPath = configuredAccessPoints.key(settingsPath);
QHashIterator<QString, QNetworkManagerInterfaceDevice*> i(interfaceDevices);
while (i.hasNext()) {
i.next();
if (i.value()->deviceType() == DEVICE_TYPE_ETHERNET &&
connectionType == DEVICE_TYPE_ETHERNET) {
dbusDevicePath = i.key();
break;
} else if (i.value()->deviceType() == DEVICE_TYPE_WIFI &&
connectionType == DEVICE_TYPE_WIFI) {
dbusDevicePath = i.key();
break;
} else if (i.value()->deviceType() == DEVICE_TYPE_MODEM &&
connectionType == DEVICE_TYPE_MODEM) {
dbusDevicePath = i.key();
break;
}
}
if (specificPath.isEmpty())
specificPath = "/";
managerInterface->activateConnection(service, QDBusObjectPath(settingsPath),
managerInterface->activateConnection(QDBusObjectPath(settingsPath),
QDBusObjectPath(dbusDevicePath), QDBusObjectPath(specificPath));
}
@ -221,13 +210,11 @@ void QNetworkManagerEngine::disconnectFromId(const QString &id)
return;
}
foreach (const QDBusObjectPath &acPath, managerInterface->activeConnections()) {
QNetworkManagerConnectionActive activeConnection(acPath.path());
const QString identifier = activeConnection.connection().path();
if (id == identifier && accessPointConfigurations.contains(id)) {
managerInterface->deactivateConnection(acPath);
QHashIterator<QString, QNetworkManagerConnectionActive*> i(activeConnectionsList);
while (i.hasNext()) {
i.next();
if (id == i.value()->connection().path() && accessPointConfigurations.contains(id)) {
managerInterface->deactivateConnection(QDBusObjectPath(i.key()));
break;
}
}
@ -250,12 +237,9 @@ void QNetworkManagerEngine::scanFinished()
QMetaObject::invokeMethod(this, "updateCompleted", Qt::QueuedConnection);
}
void QNetworkManagerEngine::interfacePropertiesChanged(const QString &path,
const QMap<QString, QVariant> &properties)
void QNetworkManagerEngine::interfacePropertiesChanged(const QMap<QString, QVariant> &properties)
{
Q_UNUSED(path)
QMutexLocker locker(&mutex);
QMapIterator<QString, QVariant> i(properties);
while (i.hasNext()) {
i.next();
@ -267,22 +251,20 @@ void QNetworkManagerEngine::interfacePropertiesChanged(const QString &path,
qdbus_cast<QList<QDBusObjectPath> >(i.value().value<QDBusArgument>());
QStringList identifiers = accessPointConfigurations.keys();
foreach (const QString &id, identifiers)
QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id);
QStringList priorActiveConnections = this->activeConnections.keys();
QStringList priorActiveConnections = activeConnectionsList.keys();
foreach (const QDBusObjectPath &acPath, activeConnections) {
priorActiveConnections.removeOne(acPath.path());
QNetworkManagerConnectionActive *activeConnection =
this->activeConnections.value(acPath.path());
activeConnectionsList.value(acPath.path());
if (!activeConnection) {
activeConnection = new QNetworkManagerConnectionActive(acPath.path(),this);
this->activeConnections.insert(acPath.path(), activeConnection);
activeConnectionsList.insert(acPath.path(), activeConnection);
connect(activeConnection, SIGNAL(propertiesChanged(QMap<QString,QVariant>)),
this, SLOT(activeConnectionPropertiesChanged(QMap<QString,QVariant>)));
activeConnection->setConnections();
connect(activeConnection, SIGNAL(propertiesChanged(QString,QMap<QString,QVariant>)),
this, SLOT(activeConnectionPropertiesChanged(QString,QMap<QString,QVariant>)));
}
const QString id = activeConnection->connection().path();
@ -295,6 +277,11 @@ void QNetworkManagerEngine::interfacePropertiesChanged(const QString &path,
if (activeConnection->state() == NM_ACTIVE_CONNECTION_STATE_ACTIVATED &&
ptr->state != QNetworkConfiguration::Active) {
ptr->state = QNetworkConfiguration::Active;
if (activeConnectionsList.value(id) && activeConnectionsList.value(id)->defaultRoute()
&& managerInterface->state() < QNetworkManagerInterface::NM_STATE_CONNECTED_GLOBAL) {
ptr->purpose = QNetworkConfiguration::PrivatePurpose;
}
ptr->mutex.unlock();
locker.unlock();
@ -307,7 +294,7 @@ void QNetworkManagerEngine::interfacePropertiesChanged(const QString &path,
}
while (!priorActiveConnections.isEmpty())
delete this->activeConnections.take(priorActiveConnections.takeFirst());
delete activeConnectionsList.take(priorActiveConnections.takeFirst());
while (!identifiers.isEmpty()) {
QNetworkConfigurationPrivatePointer ptr =
@ -330,14 +317,13 @@ void QNetworkManagerEngine::interfacePropertiesChanged(const QString &path,
}
}
void QNetworkManagerEngine::activeConnectionPropertiesChanged(const QString &path,
const QMap<QString, QVariant> &properties)
void QNetworkManagerEngine::activeConnectionPropertiesChanged(const QMap<QString, QVariant> &properties)
{
QMutexLocker locker(&mutex);
Q_UNUSED(properties)
QNetworkManagerConnectionActive *activeConnection = activeConnections.value(path);
QNetworkManagerConnectionActive *activeConnection = qobject_cast<QNetworkManagerConnectionActive *>(sender());
if (!activeConnection)
return;
@ -347,8 +333,13 @@ void QNetworkManagerEngine::activeConnectionPropertiesChanged(const QString &pat
QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id);
if (ptr) {
ptr->mutex.lock();
if (activeConnection->state() == NM_ACTIVE_CONNECTION_STATE_ACTIVATED &&
ptr->state != QNetworkConfiguration::Active) {
if (properties.value("State").toUInt() == NM_ACTIVE_CONNECTION_STATE_ACTIVATED) {
QList<QDBusObjectPath> devices = activeConnection->devices();
if (!devices.isEmpty()) {
QNetworkManagerInterfaceDevice device(devices.at(0).path(),this);
connectionInterfaces.insert(id,device.networkInterface());
}
ptr->state |= QNetworkConfiguration::Active;
ptr->mutex.unlock();
@ -356,22 +347,17 @@ void QNetworkManagerEngine::activeConnectionPropertiesChanged(const QString &pat
emit configurationChanged(ptr);
locker.relock();
} else {
connectionInterfaces.remove(id);
ptr->mutex.unlock();
}
}
}
void QNetworkManagerEngine::devicePropertiesChanged(const QString &/*path*/,quint32 /*state*/)
{
// Q_UNUSED(path);
// Q_UNUSED(state)
}
void QNetworkManagerEngine::deviceConnectionsChanged(const QStringList &activeConnectionsList)
void QNetworkManagerEngine::deviceConnectionsChanged(const QStringList &connectionsList)
{
QMutexLocker locker(&mutex);
for (int i = 0; i < connections.count(); ++i) {
if (activeConnectionsList.contains(connections.at(i)->connectionInterface()->path()))
if (connectionsList.contains(connections.at(i)->connectionInterface()->path()))
continue;
const QString settingsPath = connections.at(i)->connectionInterface()->path();
@ -392,27 +378,23 @@ void QNetworkManagerEngine::deviceConnectionsChanged(const QStringList &activeCo
void QNetworkManagerEngine::deviceAdded(const QDBusObjectPath &path)
{
QMutexLocker locker(&mutex);
QNetworkManagerInterfaceDevice *iDevice;
iDevice = new QNetworkManagerInterfaceDevice(path.path(),this);
connect(iDevice,SIGNAL(connectionsChanged(QStringList)),
this,SLOT(deviceConnectionsChanged(QStringList)));
connect(iDevice,SIGNAL(stateChanged(QString,quint32)),
this,SLOT(devicePropertiesChanged(QString,quint32)));
iDevice->setConnections();
interfaceDevices.insert(path.path(),iDevice);
if (iDevice->deviceType() == DEVICE_TYPE_WIFI) {
QNetworkManagerInterfaceDeviceWireless *wirelessDevice =
new QNetworkManagerInterfaceDeviceWireless(iDevice->connectionInterface()->path(),this);
wirelessDevice->setConnections();
connect(wirelessDevice, SIGNAL(accessPointAdded(QString)),
this, SLOT(newAccessPoint(QString)));
connect(wirelessDevice, SIGNAL(accessPointRemoved(QString)),
this, SLOT(removeAccessPoint(QString)));
connect(wirelessDevice,SIGNAL(scanDone()),this,SLOT(scanFinished()));
wirelessDevice->setConnections();
foreach (const QDBusObjectPath &apPath, wirelessDevice->getAccessPoints())
newAccessPoint(apPath.path());
@ -444,10 +426,10 @@ void QNetworkManagerEngine::newConnection(const QDBusObjectPath &path,
if (!settings)
settings = qobject_cast<QNetworkManagerSettings *>(sender());
if (!settings)
if (!settings) {
return;
}
settings->deleteLater();
QNetworkManagerSettingsConnection *connection =
new QNetworkManagerSettingsConnection(settings->connectionInterface()->service(),
path.path(),this);
@ -482,12 +464,10 @@ void QNetworkManagerEngine::newConnection(const QDBusObjectPath &path,
parseConnection(settingsPath, connection->getSettings());
// Check if connection is active.
foreach (const QDBusObjectPath &acPath, managerInterface->activeConnections()) {
QNetworkManagerConnectionActive activeConnection(acPath.path());
if (activeConnection.defaultRoute() &&
activeConnection.connection().path() == settingsPath &&
activeConnection.state() == NM_ACTIVE_CONNECTION_STATE_ACTIVATED) {
QHashIterator<QString, QNetworkManagerConnectionActive*> i(activeConnectionsList);
while (i.hasNext()) {
i.next();
if (i.value()->connection().path() == settingsPath) {
cpPriv->state |= QNetworkConfiguration::Active;
break;
}
@ -505,6 +485,7 @@ void QNetworkManagerEngine::removeConnection(const QString &path)
QNetworkManagerSettingsConnection *connection =
qobject_cast<QNetworkManagerSettingsConnection *>(sender());
if (!connection)
return;
@ -525,6 +506,7 @@ void QNetworkManagerEngine::removeConnection(const QString &path)
while (i.hasNext()) {
i.next();
if (i.value() == path) {
configuredAccessPoints.remove(i.key());
newAccessPoint(i.key());
}
}
@ -575,10 +557,9 @@ void QNetworkManagerEngine::updateConnection()
void QNetworkManagerEngine::activationFinished(QDBusPendingCallWatcher *watcher)
{
QMutexLocker locker(&mutex);
QDBusPendingReply<QDBusObjectPath> reply(*watcher);
watcher->deleteLater();
QDBusPendingReply<QDBusObjectPath> reply(*watcher);
if (!reply.isError()) {
QDBusObjectPath result = reply.value();
@ -620,15 +601,14 @@ void QNetworkManagerEngine::newAccessPoint(const QString &path)
if (okToAdd) {
accessPoints.append(accessPoint);
accessPoint->setConnections();
connect(accessPoint, SIGNAL(propertiesChanged(QMap<QString,QVariant>)),
this, SLOT(updateAccessPoint(QMap<QString,QVariant>)));
}
// Check if configuration exists for connection.
if (!accessPoint->ssid().isEmpty()) {
for (int i = 0; i < connections.count(); ++i) {
QNetworkManagerSettingsConnection *connection = connections.at(i);
const QString settingsPath = connection->connectionInterface()->path();
if (accessPoint->ssid() == connection->getSsid()) {
if (!configuredAccessPoints.contains(path)) {
configuredAccessPoints.insert(path,settingsPath);
@ -655,11 +635,7 @@ void QNetworkManagerEngine::newAccessPoint(const QString &path)
ptr->isValid = true;
ptr->id = path;
ptr->type = QNetworkConfiguration::InternetAccessPoint;
if (accessPoint->flags() == NM_802_11_AP_FLAGS_PRIVACY) {
ptr->purpose = QNetworkConfiguration::PrivatePurpose;
} else {
ptr->purpose = QNetworkConfiguration::PublicPurpose;
}
ptr->state = QNetworkConfiguration::Undefined;
ptr->bearerType = QNetworkConfiguration::BearerWLAN;
@ -674,13 +650,13 @@ void QNetworkManagerEngine::removeAccessPoint(const QString &path)
QMutexLocker locker(&mutex);
for (int i = 0; i < accessPoints.count(); ++i) {
QNetworkManagerInterfaceAccessPoint *accessPoint = accessPoints.at(i);
if (accessPoint->connectionInterface()->path() == path) {
accessPoints.removeOne(accessPoint);
if (configuredAccessPoints.contains(accessPoint->connectionInterface()->path())) {
// find connection and change state to Defined
configuredAccessPoints.remove(accessPoint->connectionInterface()->path());
for (int i = 0; i < connections.count(); ++i) {
QNetworkManagerSettingsConnection *connection = connections.at(i);
@ -705,8 +681,6 @@ void QNetworkManagerEngine::removeAccessPoint(const QString &path)
accessPointConfigurations.take(path);
if (ptr) {
locker.unlock();
locker.unlock();
emit configurationRemoved(ptr);
locker.relock();
@ -718,42 +692,9 @@ void QNetworkManagerEngine::removeAccessPoint(const QString &path)
}
}
void QNetworkManagerEngine::updateAccessPoint(const QMap<QString, QVariant> &map)
{
QMutexLocker locker(&mutex);
Q_UNUSED(map)
QNetworkManagerInterfaceAccessPoint *accessPoint =
qobject_cast<QNetworkManagerInterfaceAccessPoint *>(sender());
if (!accessPoint)
return;
accessPoint->deleteLater();
for (int i = 0; i < connections.count(); ++i) {
QNetworkManagerSettingsConnection *connection = connections.at(i);
if (accessPoint->ssid() == connection->getSsid()) {
const QString settingsPath = connection->connectionInterface()->path();
const QString connectionId = settingsPath;
QNetworkConfigurationPrivatePointer ptr =
accessPointConfigurations.value(connectionId);
ptr->mutex.lock();
QNetworkConfiguration::StateFlags flag = QNetworkConfiguration::Defined;
ptr->state = (flag | QNetworkConfiguration::Discovered);
ptr->mutex.unlock();
locker.unlock();
emit configurationChanged(ptr);
return;
}
}
}
QNetworkConfigurationPrivate *QNetworkManagerEngine::parseConnection(const QString &settingsPath,
const QNmSettingsMap &map)
{
// Q_UNUSED(service);
QMutexLocker locker(&mutex);
QNetworkConfigurationPrivate *cpPriv = new QNetworkConfigurationPrivate;
cpPriv->name = map.value("connection").value("id").toString();
@ -765,17 +706,15 @@ QNetworkConfigurationPrivate *QNetworkManagerEngine::parseConnection(const QStri
cpPriv->purpose = QNetworkConfiguration::PublicPurpose;
cpPriv->state = QNetworkConfiguration::Defined;
const QString connectionType = map.value("connection").value("type").toString();
if (connectionType == QLatin1String("802-3-ethernet")) {
cpPriv->bearerType = QNetworkConfiguration::BearerEthernet;
cpPriv->purpose = QNetworkConfiguration::PublicPurpose;
foreach (const QDBusObjectPath &devicePath, managerInterface->getDevices()) {
QNetworkManagerInterfaceDevice device(devicePath.path());
QNetworkManagerInterfaceDevice device(devicePath.path(),this);
if (device.deviceType() == DEVICE_TYPE_ETHERNET) {
QNetworkManagerInterfaceDeviceWired wiredDevice(device.connectionInterface()->path());
QNetworkManagerInterfaceDeviceWired wiredDevice(device.connectionInterface()->path(),this);
if (wiredDevice.carrier()) {
cpPriv->state |= QNetworkConfiguration::Discovered;
break;
@ -786,12 +725,6 @@ QNetworkConfigurationPrivate *QNetworkManagerEngine::parseConnection(const QStri
cpPriv->bearerType = QNetworkConfiguration::BearerWLAN;
const QString connectionSsid = map.value("802-11-wireless").value("ssid").toString();
const QString connectionSecurity = map.value("802-11-wireless").value("security").toString();
if (!connectionSecurity.isEmpty()) {
cpPriv->purpose = QNetworkConfiguration::PrivatePurpose;
} else {
cpPriv->purpose = QNetworkConfiguration::PublicPurpose;
}
for (int i = 0; i < accessPoints.count(); ++i) {
if (connectionSsid == accessPoints.at(i)->ssid()
&& map.value("802-11-wireless").value("seen-bssids").toStringList().contains(accessPoints.at(i)->hwAddress())) {
@ -813,32 +746,12 @@ QNetworkConfigurationPrivate *QNetworkManagerEngine::parseConnection(const QStri
}
}
} else if (connectionType == QLatin1String("gsm")) {
foreach (const QDBusObjectPath &devicePath, managerInterface->getDevices()) {
QNetworkManagerInterfaceDevice device(devicePath.path());
if (device.deviceType() == DEVICE_TYPE_MODEM) {
QNetworkManagerInterfaceDeviceModem deviceModem(device.connectionInterface()->path(),this);
switch (deviceModem.currentCapabilities()) {
case 2:
cpPriv->bearerType = QNetworkConfiguration::Bearer2G;
break;
case 4:
cpPriv->bearerType = QNetworkConfiguration::Bearer3G;
break;
case 8:
cpPriv->bearerType = QNetworkConfiguration::Bearer4G;
break;
default:
cpPriv->bearerType = QNetworkConfiguration::BearerUnknown;
break;
};
}
}
cpPriv->purpose = QNetworkConfiguration::PrivatePurpose;
cpPriv->bearerType = currentBearerType();
if (map.value("connection").contains("timestamp")) {
cpPriv->state |= QNetworkConfiguration::Discovered;
}
cpPriv->name = contextName(map.value("connection").value("id").toString());
}
return cpPriv;
}
@ -857,7 +770,6 @@ QNetworkManagerSettingsConnection *QNetworkManagerEngine::connectionFromId(const
QNetworkSession::State QNetworkManagerEngine::sessionStateForId(const QString &id)
{
QMutexLocker locker(&mutex);
QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id);
if (!ptr)
@ -866,8 +778,8 @@ QNetworkSession::State QNetworkManagerEngine::sessionStateForId(const QString &i
if (!ptr->isValid)
return QNetworkSession::Invalid;
foreach (const QString &acPath, activeConnections.keys()) {
QNetworkManagerConnectionActive *activeConnection = activeConnections.value(acPath);
foreach (const QString &acPath, activeConnectionsList.keys()) {
QNetworkManagerConnectionActive *activeConnection = activeConnectionsList.value(acPath);
const QString identifier = activeConnection->connection().path();
@ -899,7 +811,7 @@ quint64 QNetworkManagerEngine::bytesWritten(const QString &id)
QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id);
if (ptr && (ptr->state & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) {
const QString networkInterface = getInterfaceFromId(id);
const QString networkInterface = connectionInterfaces.value(id);
if (!networkInterface.isEmpty()) {
const QString devFile = QLatin1String("/sys/class/net/") +
networkInterface +
@ -927,7 +839,7 @@ quint64 QNetworkManagerEngine::bytesReceived(const QString &id)
QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id);
if (ptr && (ptr->state & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) {
const QString networkInterface = getInterfaceFromId(id);
const QString networkInterface = connectionInterfaces.value(id);
if (!networkInterface.isEmpty()) {
const QString devFile = QLatin1String("/sys/class/net/") +
networkInterface +
@ -977,6 +889,54 @@ QNetworkConfigurationPrivatePointer QNetworkManagerEngine::defaultConfiguration(
return QNetworkConfigurationPrivatePointer();
}
void QNetworkManagerEngine::changedModem()
{
if (ofonoNetwork)
delete ofonoNetwork;
ofonoNetwork = new QOfonoNetworkRegistrationInterface(ofonoManager->currentModem(),this);
if (ofonoContextManager)
delete ofonoContextManager;
ofonoContextManager = new QOfonoDataConnectionManagerInterface(ofonoManager->currentModem(),this);
}
QNetworkConfiguration::BearerType QNetworkManagerEngine::currentBearerType()
{
if (ofonoContextManager) {
QString bearer = ofonoContextManager->bearer();
if (bearer == QLatin1String("gsm")) {
return QNetworkConfiguration::Bearer2G;
} else if (bearer == QLatin1String("edge")) {
return QNetworkConfiguration::Bearer2G;
} else if (bearer == QLatin1String("umts")) {
return QNetworkConfiguration::BearerWCDMA;
} else if (bearer == QLatin1String("hspa")
|| bearer == QLatin1String("hsdpa")
|| bearer == QLatin1String("hsupa")) {
return QNetworkConfiguration::BearerHSPA;
} else if (bearer == QLatin1String("lte")) {
return QNetworkConfiguration::BearerLTE;
}
}
return QNetworkConfiguration::BearerUnknown;
}
QString QNetworkManagerEngine::contextName(const QString &path)
{
if (ofonoContextManager) {
QString contextPart = path.section('/', -1);
Q_FOREACH (const QString &oContext, ofonoContextManager->contexts()) {
if (oContext.contains(contextPart)) {
QOfonoConnectionContextInterface contextInterface(oContext,this);
return contextInterface.name();
}
}
}
return path;
}
QT_END_NAMESPACE
#endif // QT_NO_DBUS

View File

@ -49,6 +49,8 @@
#include "qnetworkmanagerservice.h"
#include "../linux_common/qofonoservice_linux_p.h"
#include <QMap>
#include <QVariant>
@ -89,11 +91,8 @@ public:
QNetworkConfigurationPrivatePointer defaultConfiguration();
private Q_SLOTS:
void interfacePropertiesChanged(const QString &path,
const QMap<QString, QVariant> &properties);
void activeConnectionPropertiesChanged(const QString &path,
const QMap<QString, QVariant> &properties);
void devicePropertiesChanged(const QString &path, quint32);
void interfacePropertiesChanged(const QMap<QString, QVariant> &properties);
void activeConnectionPropertiesChanged(const QMap<QString, QVariant> &properties);
void deviceAdded(const QDBusObjectPath &path);
void deviceRemoved(const QDBusObjectPath &path);
@ -106,8 +105,8 @@ private Q_SLOTS:
void newAccessPoint(const QString &path);
void removeAccessPoint(const QString &path);
void updateAccessPoint(const QMap<QString, QVariant> &map);
void scanFinished();
void changedModem();
private:
QNetworkConfigurationPrivate *parseConnection(const QString &settingsPath,
@ -116,14 +115,21 @@ private:
QNetworkManagerInterface *managerInterface;
QNetworkManagerSettings *systemSettings;
QNetworkManagerSettings *userSettings;
QHash<QString, QNetworkManagerInterfaceDeviceWireless *> wirelessDevices;
QHash<QString, QNetworkManagerConnectionActive *> activeConnections;
QHash<QString, QNetworkManagerConnectionActive *> activeConnectionsList;
QList<QNetworkManagerSettingsConnection *> connections;
QList<QNetworkManagerInterfaceAccessPoint *> accessPoints;
QHash<QString, QNetworkManagerInterfaceDevice *> interfaceDevices;
QMap<QString,QString> configuredAccessPoints; //ap, settings path
QHash<QString,QString> connectionInterfaces; // ac, interface
QOfonoManagerInterface *ofonoManager;
QOfonoNetworkRegistrationInterface *ofonoNetwork;
QOfonoDataConnectionManagerInterface *ofonoContextManager;
QNetworkConfiguration::BearerType currentBearerType();
QString contextName(const QString &path);
};
QT_END_NAMESPACE

File diff suppressed because it is too large Load Diff

View File

@ -56,7 +56,6 @@
#include <QtDBus/QDBusObjectPath>
#include <QtDBus/QDBusContext>
#include <QMap>
#include "qnmdbushelper.h"
#ifndef QT_NO_DBUS
@ -89,7 +88,7 @@ typedef enum
NM_ACTIVE_CONNECTION_STATE_UNKNOWN = 0,
NM_ACTIVE_CONNECTION_STATE_ACTIVATING,
NM_ACTIVE_CONNECTION_STATE_ACTIVATED,
NM_ACTIVE_CONNECTION_STATE_DEACTIVATED
NM_ACTIVE_CONNECTION_STATE_DEACTIVATED = 4
} NMActiveConnectionState;
#define NM_DBUS_SERVICE "org.freedesktop.NetworkManager"
@ -135,12 +134,23 @@ class QNetworkManagerInterface : public QObject
Q_OBJECT
public:
typedef enum
{
NM_STATE_UNKNOWN = 0,
NM_STATE_ASLEEP = 10,
NM_STATE_DISCONNECTED = 20,
NM_STATE_DISCONNECTING = 30,
NM_STATE_CONNECTING = 40,
NM_STATE_CONNECTED_LOCAL = 50,
NM_STATE_CONNECTED_SITE = 60,
NM_STATE_CONNECTED_GLOBAL = 70
} NMState;
QNetworkManagerInterface(QObject *parent = 0);
~QNetworkManagerInterface();
QList <QDBusObjectPath> getDevices() const;
void activateConnection(const QString &serviceName, QDBusObjectPath connection, QDBusObjectPath device, QDBusObjectPath specificObject);
QList <QDBusObjectPath> getDevices();
void activateConnection(QDBusObjectPath connection,QDBusObjectPath device, QDBusObjectPath specificObject);
void deactivateConnection(QDBusObjectPath connectionPath) const;
QDBusObjectPath path() const;
@ -149,21 +159,28 @@ public:
bool wirelessEnabled() const;
bool wirelessHardwareEnabled() const;
QList <QDBusObjectPath> activeConnections() const;
quint32 state();
NMState state();
QString version() const;
bool setConnections();
bool isValid();
Q_SIGNALS:
void deviceAdded(QDBusObjectPath);
void deviceRemoved(QDBusObjectPath);
void propertiesChanged( const QString &, QMap<QString,QVariant>);
void stateChanged(const QString&, quint32);
void propertiesChanged(QMap<QString,QVariant>);
void stateChanged(quint32);
void activationFinished(QDBusPendingCallWatcher*);
void propertiesReady();
void devicesListReady();
private Q_SLOTS:
void propertiesSwap(QMap<QString,QVariant>);
private:
QNetworkManagerInterfacePrivate *d;
QNmDBusHelper *nmDBusHelper;
QVariantMap propertyMap;
QList<QDBusObjectPath> devicesPathList;
};
class QNetworkManagerInterfaceAccessPointPrivate;
@ -228,11 +245,14 @@ public:
Q_SIGNALS:
void propertiesChanged(QMap <QString,QVariant>);
void propertiesChanged( const QString &, QMap<QString,QVariant>);
void propertiesReady();
private Q_SLOTS:
void propertiesSwap(QMap<QString,QVariant>);
private:
QNetworkManagerInterfaceAccessPointPrivate *d;
QNmDBusHelper *nmDBusHelper;
QVariantMap propertyMap;
};
class QNetworkManagerInterfaceDevicePrivate;
@ -258,11 +278,14 @@ public:
Q_SIGNALS:
void stateChanged(const QString &, quint32);
void propertiesChanged(const QString &, QMap<QString,QVariant>);
void propertiesChanged(QMap<QString,QVariant>);
void connectionsChanged(QStringList);
void propertiesReady();
private Q_SLOTS:
void propertiesSwap(QMap<QString,QVariant>);
private:
QNetworkManagerInterfaceDevicePrivate *d;
QNmDBusHelper *nmDBusHelper;
QVariantMap propertyMap;
};
class QNetworkManagerInterfaceDeviceWiredPrivate;
@ -284,10 +307,15 @@ public:
bool isValid();
Q_SIGNALS:
void propertiesChanged( const QString &, QMap<QString,QVariant>);
void propertiesChanged(QMap<QString,QVariant>);
void propertiesReady();
private Q_SLOTS:
void propertiesSwap(QMap<QString,QVariant>);
private:
QNetworkManagerInterfaceDeviceWiredPrivate *d;
QNmDBusHelper *nmDBusHelper;
QVariantMap propertyMap;
};
class QNetworkManagerInterfaceDeviceWirelessPrivate;
@ -325,15 +353,24 @@ public:
void requestScan();
Q_SIGNALS:
void propertiesChanged( const QString &, QMap<QString,QVariant>);
void propertiesChanged(QMap<QString,QVariant>);
void accessPointAdded(const QString &);
void accessPointRemoved(const QString &);
void scanDone();
void propertiesReady();
void accessPointsReady();
private Q_SLOTS:
void scanIsDone();
void propertiesSwap(QMap<QString,QVariant>);
void slotAccessPointAdded(QDBusObjectPath);
void slotAccessPointRemoved(QDBusObjectPath);
private:
QNetworkManagerInterfaceDeviceWirelessPrivate *d;
QNmDBusHelper *nmDBusHelper;
QVariantMap propertyMap;
QList <QDBusObjectPath> accessPointsList;
};
class QNetworkManagerInterfaceDeviceModemPrivate;
@ -350,6 +387,7 @@ public:
Gsm_Umts = 0x4,
Lte = 0x08
};
Q_DECLARE_FLAGS(ModemCapabilities, ModemCapability)
explicit QNetworkManagerInterfaceDeviceModem(const QString &ifaceDevicePath,
QObject *parent = 0);
@ -361,16 +399,22 @@ public:
bool setConnections();
bool isValid();
quint32 modemCapabilities() const;
quint32 currentCapabilities() const;
ModemCapabilities modemCapabilities() const;
ModemCapabilities currentCapabilities() const;
Q_SIGNALS:
void propertiesChanged( const QString &, QMap<QString,QVariant>);
void propertiesChanged(QMap<QString,QVariant>);
void propertiesReady();
private Q_SLOTS:
void propertiesSwap(QMap<QString,QVariant>);
private:
QNetworkManagerInterfaceDeviceModemPrivate *d;
QNmDBusHelper *nmDBusHelper;
QVariantMap propertyMap;
};
Q_DECLARE_OPERATORS_FOR_FLAGS(QNetworkManagerInterfaceDeviceModem::ModemCapabilities)
class QNetworkManagerSettingsPrivate;
class QNetworkManagerSettings : public QObject
@ -390,8 +434,10 @@ public:
Q_SIGNALS:
void newConnection(QDBusObjectPath);
void connectionsListReady();
private:
QNetworkManagerSettingsPrivate *d;
QList <QDBusObjectPath> connectionsList;
};
class QNetworkManagerSettingsConnectionPrivate;
@ -418,12 +464,14 @@ public:
bool isValid();
Q_SIGNALS:
void updated();
void removed(const QString &path);
void settingsReady();
private Q_SLOTS:
void slotSettingsRemoved();
private:
QNmDBusHelper *nmDBusHelper;
QNetworkManagerSettingsConnectionPrivate *d;
};
@ -444,7 +492,6 @@ public:
~ QNetworkManagerConnectionActive();
QDBusInterface *connectionInterface() const;
QString serviceName() const;
QDBusObjectPath connection() const;
QDBusObjectPath specificObject() const;
QList<QDBusObjectPath> devices() const;
@ -455,11 +502,15 @@ public:
Q_SIGNALS:
void propertiesChanged(QList<QDBusObjectPath>);
void propertiesChanged( const QString &, QMap<QString,QVariant>);
void propertiesChanged(QMap<QString,QVariant>);
void propertiesReady();
private Q_SLOTS:
void propertiesSwap(QMap<QString,QVariant>);
private:
QNetworkManagerConnectionActivePrivate *d;
QNmDBusHelper *nmDBusHelper;
QVariantMap propertyMap;
};
class QNetworkManagerIp4ConfigPrivate;

View File

@ -1,140 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the plugins of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL21$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** $QT_END_LICENSE$
**
****************************************************************************/
// this class is for helping qdbus get stuff
#include "qnmdbushelper.h"
#include "qnetworkmanagerservice.h"
#include <QDBusError>
#include <QDBusInterface>
#include <QDBusMessage>
#include <QDBusReply>
#include <QDebug>
#ifndef QT_NO_DBUS
QT_BEGIN_NAMESPACE
QNmDBusHelper::QNmDBusHelper(QObject * parent)
: QObject(parent)
{
}
QNmDBusHelper::~QNmDBusHelper()
{
}
void QNmDBusHelper::deviceStateChanged(quint32 state)
{
QDBusMessage msg = this->message();
if (state == NM_DEVICE_STATE_ACTIVATED
|| state == NM_DEVICE_STATE_DISCONNECTED
|| state == NM_DEVICE_STATE_UNAVAILABLE
|| state == NM_DEVICE_STATE_FAILED) {
emit pathForStateChanged(msg.path(), state);
}
}
void QNmDBusHelper::slotAccessPointAdded(QDBusObjectPath path)
{
if (path.path().length() > 2)
emit pathForAccessPointAdded(path.path());
}
void QNmDBusHelper::slotAccessPointRemoved(QDBusObjectPath path)
{
if (path.path().length() > 2)
emit pathForAccessPointRemoved(path.path());
}
void QNmDBusHelper::slotPropertiesChanged(QMap<QString,QVariant> map)
{
QDBusMessage msg = this->message();
QMapIterator<QString, QVariant> i(map);
while (i.hasNext()) {
i.next();
if (i.key() == QStringLiteral("State")) {
quint32 state = i.value().toUInt();
if (state == NM_DEVICE_STATE_ACTIVATED
|| state == NM_DEVICE_STATE_DISCONNECTED
|| state == NM_DEVICE_STATE_UNAVAILABLE
|| state == NM_DEVICE_STATE_FAILED) {
emit pathForPropertiesChanged(msg.path(), map);
}
} else if (i.key() == QStringLiteral("ActiveAccessPoint")) {
emit pathForPropertiesChanged(msg.path(), map);
} else if (i.key() == QStringLiteral("ActiveConnections")) {
emit pathForPropertiesChanged(msg.path(), map);
} else if (i.key() == QStringLiteral("AvailableConnections")) {
const QDBusArgument &dbusArgs = i.value().value<QDBusArgument>();
QDBusObjectPath path;
QStringList paths;
dbusArgs.beginArray();
while (!dbusArgs.atEnd()) {
dbusArgs >> path;
paths << path.path();
}
dbusArgs.endArray();
emit pathForConnectionsChanged(paths);
}
}
}
void QNmDBusHelper::slotSettingsRemoved()
{
QDBusMessage msg = this->message();
emit pathForSettingsRemoved(msg.path());
}
void QNmDBusHelper::activeConnectionPropertiesChanged(QMap<QString,QVariant> map)
{
QDBusMessage msg = this->message();
QMapIterator<QString, QVariant> i(map);
while (i.hasNext()) {
i.next();
if (i.key() == QStringLiteral("State")) {
quint32 state = i.value().toUInt();
if (state == NM_ACTIVE_CONNECTION_STATE_ACTIVATED
|| state == NM_ACTIVE_CONNECTION_STATE_DEACTIVATED) {
emit pathForPropertiesChanged(msg.path(), map);
}
}
}
}
QT_END_NAMESPACE
#endif // QT_NO_DBUS

View File

@ -1,73 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the plugins of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL21$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QNMDBUSHELPERPRIVATE_H
#define QNMDBUSHELPERPRIVATE_H
#include <QDBusObjectPath>
#include <QDBusContext>
#include <QMap>
#ifndef QT_NO_DBUS
QT_BEGIN_NAMESPACE
class QNmDBusHelper: public QObject, protected QDBusContext
{
Q_OBJECT
public:
QNmDBusHelper(QObject *parent = 0);
~QNmDBusHelper();
public slots:
void deviceStateChanged(quint32);
void slotAccessPointAdded(QDBusObjectPath);
void slotAccessPointRemoved(QDBusObjectPath);
void slotPropertiesChanged(QMap<QString,QVariant>);
void slotSettingsRemoved();
void activeConnectionPropertiesChanged(QMap<QString,QVariant>);
Q_SIGNALS:
void pathForStateChanged(const QString &, quint32);
void pathForAccessPointAdded(const QString &);
void pathForAccessPointRemoved(const QString &);
void pathForPropertiesChanged(const QString &, QMap<QString,QVariant>);
void pathForSettingsRemoved(const QString &);
void pathForConnectionsChanged(const QStringList &pathsList);
};
QT_END_NAMESPACE
#endif // QT_NO_DBUS
#endif// QNMDBUSHELPERPRIVATE_H