summaryrefslogtreecommitdiffstats
path: root/src/plugins/bearer/generic
diff options
context:
space:
mode:
authorAaron McCarthy <aaron.mccarthy@nokia.com>2009-12-07 06:11:11 (GMT)
committerAaron McCarthy <aaron.mccarthy@nokia.com>2010-01-04 01:00:58 (GMT)
commit63d59200884a68e569cce9d0ee470447b8239f6b (patch)
tree80c4f5086a4c0ba6300c8a7588a55a7d9f8e5b19 /src/plugins/bearer/generic
parent19e64169b8f3b0b0c12d99327e8c68c5c8a26498 (diff)
downloadQt-63d59200884a68e569cce9d0ee470447b8239f6b.zip
Qt-63d59200884a68e569cce9d0ee470447b8239f6b.tar.gz
Qt-63d59200884a68e569cce9d0ee470447b8239f6b.tar.bz2
Convert generic engine plugin to be incremental.
Diffstat (limited to 'src/plugins/bearer/generic')
-rw-r--r--src/plugins/bearer/generic/qgenericengine.cpp149
-rw-r--r--src/plugins/bearer/generic/qgenericengine.h4
2 files changed, 100 insertions, 53 deletions
diff --git a/src/plugins/bearer/generic/qgenericengine.cpp b/src/plugins/bearer/generic/qgenericengine.cpp
index 4be27ba..11dfb3e 100644
--- a/src/plugins/bearer/generic/qgenericengine.cpp
+++ b/src/plugins/bearer/generic/qgenericengine.cpp
@@ -125,21 +125,58 @@ static QString qGetInterfaceType(const QString &interface)
QGenericEngine::QGenericEngine(QObject *parent)
: QNetworkSessionEngine(parent)
{
- connect(&pollTimer, SIGNAL(timeout()), this, SIGNAL(configurationsChanged()));
+ connect(&pollTimer, SIGNAL(timeout()), this, SLOT(doRequestUpdate()));
pollTimer.setInterval(10000);
+ doRequestUpdate();
}
QGenericEngine::~QGenericEngine()
{
}
-QList<QNetworkConfigurationPrivate *> QGenericEngine::getConfigurations(bool *ok)
+QString QGenericEngine::getInterfaceFromId(const QString &id)
+{
+ return configurationInterface.value(id.toUInt());
+}
+
+bool QGenericEngine::hasIdentifier(const QString &id)
+{
+ return configurationInterface.contains(id.toUInt());
+}
+
+QString QGenericEngine::bearerName(const QString &id)
+{
+ QString interface = getInterfaceFromId(id);
+
+ if (interface.isEmpty())
+ return QString();
+
+ return qGetInterfaceType(interface);
+}
+
+void QGenericEngine::connectToId(const QString &id)
+{
+ emit connectionError(id, OperationNotSupported);
+}
+
+void QGenericEngine::disconnectFromId(const QString &id)
+{
+ emit connectionError(id, OperationNotSupported);
+}
+
+void QGenericEngine::requestUpdate()
{
- if (ok)
- *ok = true;
+ pollTimer.stop();
+ QTimer::singleShot(0, this, SLOT(doRequestUpdate()));
+}
- QList<QNetworkConfigurationPrivate *> foundConfigurations;
+QGenericEngine *QGenericEngine::instance()
+{
+ return genericEngine();
+}
+void QGenericEngine::doRequestUpdate()
+{
// Immediately after connecting with a wireless access point
// QNetworkInterface::allInterfaces() will sometimes return an empty list. Calling it again a
// second time results in a non-empty list. If we loose interfaces we will end up removing
@@ -148,6 +185,8 @@ QList<QNetworkConfigurationPrivate *> QGenericEngine::getConfigurations(bool *ok
if (interfaces.isEmpty())
interfaces = QNetworkInterface::allInterfaces();
+ QStringList previous = accessPointConfigurations.keys();
+
// create configuration for each interface
while (!interfaces.isEmpty()) {
QNetworkInterface interface = interfaces.takeFirst();
@@ -163,71 +202,77 @@ QList<QNetworkConfigurationPrivate *> QGenericEngine::getConfigurations(bool *ok
if (qGetInterfaceType(interface.name()) == QLatin1String("WLAN"))
continue;
- QNetworkConfigurationPrivate *cpPriv = new QNetworkConfigurationPrivate;
- const QString humanReadableName = interface.humanReadableName();
- cpPriv->name = humanReadableName.isEmpty() ? interface.name() : humanReadableName;
- cpPriv->isValid = true;
-
uint identifier;
if (interface.index())
- identifier = qHash(QLatin1String("NLA:") + QString::number(interface.index()));
+ identifier = qHash(QLatin1String("generic:") + QString::number(interface.index()));
else
- identifier = qHash(QLatin1String("NLA:") + interface.hardwareAddress());
+ identifier = qHash(QLatin1String("generic:") + interface.hardwareAddress());
+
+ const QString id = QString::number(identifier);
- cpPriv->id = QString::number(identifier);
- cpPriv->state = QNetworkConfiguration::Discovered;
- cpPriv->type = QNetworkConfiguration::InternetAccessPoint;
+ previous.removeAll(id);
+
+ QString name = interface.humanReadableName();
+ if (name.isEmpty())
+ name = interface.name();
+
+ QNetworkConfiguration::StateFlags state = QNetworkConfiguration::Discovered;
if (interface.flags() & QNetworkInterface::IsUp)
- cpPriv->state |= QNetworkConfiguration::Active;
+ state |= QNetworkConfiguration::Active;
- configurationInterface[identifier] = interface.name();
+ if (accessPointConfigurations.contains(id)) {
+ QExplicitlySharedDataPointer<QNetworkConfigurationPrivate> ptr =
+ accessPointConfigurations.value(id);
- foundConfigurations.append(cpPriv);
- }
+ bool changed = false;
- pollTimer.start();
+ if (!ptr->isValid) {
+ ptr->isValid = true;
+ changed = true;
+ }
- return foundConfigurations;
-}
+ if (ptr->name != name) {
+ ptr->name = name;
+ changed = true;
+ }
-QString QGenericEngine::getInterfaceFromId(const QString &id)
-{
- return configurationInterface.value(id.toUInt());
-}
+ if (ptr->id != id) {
+ ptr->id = id;
+ changed = true;
+ }
-bool QGenericEngine::hasIdentifier(const QString &id)
-{
- return configurationInterface.contains(id.toUInt());
-}
+ if (ptr->state != state) {
+ ptr->state = state;
+ changed = true;
+ }
-QString QGenericEngine::bearerName(const QString &id)
-{
- QString interface = getInterfaceFromId(id);
+ if (changed)
+ emit configurationChanged(ptr);
+ } else {
+ QExplicitlySharedDataPointer<QNetworkConfigurationPrivate> ptr(new QNetworkConfigurationPrivate);
- if (interface.isEmpty())
- return QString();
+ ptr->name = name;
+ ptr->isValid = true;
+ ptr->id = id;
+ ptr->state = state;
+ ptr->type = QNetworkConfiguration::InternetAccessPoint;
- return qGetInterfaceType(interface);
-}
+ accessPointConfigurations.insert(id, ptr);
-void QGenericEngine::connectToId(const QString &id)
-{
- emit connectionError(id, OperationNotSupported);
-}
+ emit configurationAdded(ptr);
+ }
+ }
-void QGenericEngine::disconnectFromId(const QString &id)
-{
- emit connectionError(id, OperationNotSupported);
-}
+ while (!previous.isEmpty()) {
+ QExplicitlySharedDataPointer<QNetworkConfigurationPrivate> ptr =
+ accessPointConfigurations.take(previous.takeFirst());
-void QGenericEngine::requestUpdate()
-{
- emit configurationsChanged();
-}
+ emit configurationRemoved(ptr);
+ }
-QGenericEngine *QGenericEngine::instance()
-{
- return genericEngine();
+ pollTimer.start();
+
+ emit updateCompleted();
}
QT_END_NAMESPACE
diff --git a/src/plugins/bearer/generic/qgenericengine.h b/src/plugins/bearer/generic/qgenericengine.h
index 9923a9b..62f964a 100644
--- a/src/plugins/bearer/generic/qgenericengine.h
+++ b/src/plugins/bearer/generic/qgenericengine.h
@@ -59,7 +59,6 @@ public:
QGenericEngine(QObject *parent = 0);
~QGenericEngine();
- QList<QNetworkConfigurationPrivate *> getConfigurations(bool *ok = 0);
QString getInterfaceFromId(const QString &id);
bool hasIdentifier(const QString &id);
@@ -72,6 +71,9 @@ public:
static QGenericEngine *instance();
+private Q_SLOTS:
+ void doRequestUpdate();
+
private:
QMap<uint, QString> configurationInterface;
QTimer pollTimer;