summaryrefslogtreecommitdiffstats
path: root/src/plugins/bearer/generic
diff options
context:
space:
mode:
authorQt Continuous Integration System <qt-info@nokia.com>2010-02-20 05:50:12 (GMT)
committerQt Continuous Integration System <qt-info@nokia.com>2010-02-20 05:50:12 (GMT)
commit1449a1b84f12d937b56ae2b9f4a3ba3dc704281e (patch)
tree04371e32433d58f19c51de2df2a89193d6914c3c /src/plugins/bearer/generic
parent8f10ca802dee1ed110f301191c4a56a85575033c (diff)
parent840dab97ee4bd68dcf75cfd2edd5e58c38040ae1 (diff)
downloadQt-1449a1b84f12d937b56ae2b9f4a3ba3dc704281e.zip
Qt-1449a1b84f12d937b56ae2b9f4a3ba3dc704281e.tar.gz
Qt-1449a1b84f12d937b56ae2b9f4a3ba3dc704281e.tar.bz2
Merge branch 'master' of scm.dev.nokia.troll.no:qt/mobility-staging into master-integration
* 'master' of scm.dev.nokia.troll.no:qt/mobility-staging: (114 commits) Create unit-test in parent directory. Allow QNAM to be created as a global variable. Don't load NetworkManager plugin in NetworkManager is not available. Disable NLA plugin, build generic on win32 and mac. Fix QNetworkSession unit test. Fix segfault. Remove debug output. Make this a warning. Don't block forever if no bearer plugins are loaded. Always build generic plugin when building NetworkManager plugin. Add QT_MODULE headers. Change docs: "phone" -> "device". Remove unused code. Simplify. Optimise iterations over QHash. Use snippets. Reorder members to remove hole. Expand documentation for QNAM::setConfiguration() and friends. Fix build on Windows, typo. Fix build on Windows. ...
Diffstat (limited to 'src/plugins/bearer/generic')
-rw-r--r--src/plugins/bearer/generic/generic.pro16
-rw-r--r--src/plugins/bearer/generic/main.cpp84
-rw-r--r--src/plugins/bearer/generic/qgenericengine.cpp323
-rw-r--r--src/plugins/bearer/generic/qgenericengine.h92
4 files changed, 515 insertions, 0 deletions
diff --git a/src/plugins/bearer/generic/generic.pro b/src/plugins/bearer/generic/generic.pro
new file mode 100644
index 0000000..1d141fd
--- /dev/null
+++ b/src/plugins/bearer/generic/generic.pro
@@ -0,0 +1,16 @@
+TARGET = qgenericbearer
+include(../../qpluginbase.pri)
+
+QT += network
+
+HEADERS += qgenericengine.h \
+ ../qnetworksession_impl.h \
+ ../qbearerengine_impl.h \
+ ../platformdefs_win.h
+SOURCES += qgenericengine.cpp \
+ ../qnetworksession_impl.cpp \
+ main.cpp
+
+QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/bearer
+target.path += $$[QT_INSTALL_PLUGINS]/bearer
+INSTALLS += target
diff --git a/src/plugins/bearer/generic/main.cpp b/src/plugins/bearer/generic/main.cpp
new file mode 100644
index 0000000..ba85d93
--- /dev/null
+++ b/src/plugins/bearer/generic/main.cpp
@@ -0,0 +1,84 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the plugins of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** 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 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qgenericengine.h"
+
+#include <QtNetwork/private/qbearerplugin_p.h>
+
+#include <QtCore/qdebug.h>
+
+QT_BEGIN_NAMESPACE
+
+class QGenericEnginePlugin : public QBearerEnginePlugin
+{
+public:
+ QGenericEnginePlugin();
+ ~QGenericEnginePlugin();
+
+ QStringList keys() const;
+ QBearerEngine *create(const QString &key) const;
+};
+
+QGenericEnginePlugin::QGenericEnginePlugin()
+{
+}
+
+QGenericEnginePlugin::~QGenericEnginePlugin()
+{
+}
+
+QStringList QGenericEnginePlugin::keys() const
+{
+ return QStringList() << QLatin1String("generic");
+}
+
+QBearerEngine *QGenericEnginePlugin::create(const QString &key) const
+{
+ if (key == QLatin1String("generic"))
+ return new QGenericEngine;
+ else
+ return 0;
+}
+
+Q_EXPORT_STATIC_PLUGIN(QGenericEnginePlugin)
+Q_EXPORT_PLUGIN2(qgenericbearer, QGenericEnginePlugin)
+
+QT_END_NAMESPACE
diff --git a/src/plugins/bearer/generic/qgenericengine.cpp b/src/plugins/bearer/generic/qgenericengine.cpp
new file mode 100644
index 0000000..dba2c08
--- /dev/null
+++ b/src/plugins/bearer/generic/qgenericengine.cpp
@@ -0,0 +1,323 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the plugins of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** 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 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qgenericengine.h"
+#include "../qnetworksession_impl.h"
+
+#include <QtNetwork/private/qnetworkconfiguration_p.h>
+
+#include <QtCore/qthread.h>
+#include <QtCore/qmutex.h>
+#include <QtCore/qcoreapplication.h>
+#include <QtCore/qstringlist.h>
+
+#include <QtCore/qdebug.h>
+
+#ifdef Q_OS_WIN
+#include "../platformdefs_win.h"
+#endif
+
+#ifdef Q_OS_LINUX
+#include <sys/socket.h>
+#include <sys/ioctl.h>
+#include <net/if.h>
+#include <net/if_arp.h>
+#endif
+
+
+static QString qGetInterfaceType(const QString &interface)
+{
+#ifdef Q_OS_WIN32
+ unsigned long oid;
+ DWORD bytesWritten;
+
+ NDIS_MEDIUM medium;
+ NDIS_PHYSICAL_MEDIUM physicalMedium;
+
+ HANDLE handle = CreateFile((TCHAR *)QString("\\\\.\\%1").arg(interface).utf16(), 0,
+ FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0);
+ if (handle == INVALID_HANDLE_VALUE)
+ return QLatin1String("Unknown");
+
+ oid = OID_GEN_MEDIA_SUPPORTED;
+ bytesWritten = 0;
+ bool result = DeviceIoControl(handle, IOCTL_NDIS_QUERY_GLOBAL_STATS, &oid, sizeof(oid),
+ &medium, sizeof(medium), &bytesWritten, 0);
+ if (!result) {
+ CloseHandle(handle);
+ return QLatin1String("Unknown");
+ }
+
+ oid = OID_GEN_PHYSICAL_MEDIUM;
+ bytesWritten = 0;
+ result = DeviceIoControl(handle, IOCTL_NDIS_QUERY_GLOBAL_STATS, &oid, sizeof(oid),
+ &physicalMedium, sizeof(physicalMedium), &bytesWritten, 0);
+ if (!result) {
+ CloseHandle(handle);
+
+ if (medium == NdisMedium802_3)
+ return QLatin1String("Ethernet");
+ else
+ return QLatin1String("Unknown");
+ }
+
+ CloseHandle(handle);
+
+ if (medium == NdisMedium802_3) {
+ switch (physicalMedium) {
+ case NdisPhysicalMediumWirelessLan:
+ return QLatin1String("WLAN");
+ case NdisPhysicalMediumBluetooth:
+ return QLatin1String("Bluetooth");
+ case NdisPhysicalMediumWiMax:
+ return QLatin1String("WiMAX");
+ default:
+#ifdef BEARER_MANAGEMENT_DEBUG
+ qDebug() << "Physical Medium" << physicalMedium;
+#endif
+ return QLatin1String("Ethernet");
+ }
+ }
+
+#ifdef BEARER_MANAGEMENT_DEBUG
+ qDebug() << medium << physicalMedium;
+#endif
+#elif defined(Q_OS_LINUX)
+ int sock = socket(AF_INET, SOCK_DGRAM, 0);
+
+ ifreq request;
+ strncpy(request.ifr_name, interface.toLocal8Bit().data(), sizeof(request.ifr_name));
+ if (ioctl(sock, SIOCGIFHWADDR, &request) >= 0) {
+ switch (request.ifr_hwaddr.sa_family) {
+ case ARPHRD_ETHER:
+ return QLatin1String("Ethernet");
+ }
+ }
+
+ close(sock);
+#else
+ Q_UNUSED(interface);
+#endif
+
+ return QLatin1String("Unknown");
+}
+
+QGenericEngine::QGenericEngine(QObject *parent)
+: QBearerEngineImpl(parent)
+{
+ connect(&pollTimer, SIGNAL(timeout()), this, SLOT(doRequestUpdate()));
+ pollTimer.setInterval(10000);
+ doRequestUpdate();
+}
+
+QGenericEngine::~QGenericEngine()
+{
+}
+
+QString QGenericEngine::getInterfaceFromId(const QString &id)
+{
+ return configurationInterface.value(id);
+}
+
+bool QGenericEngine::hasIdentifier(const QString &id)
+{
+ return configurationInterface.contains(id);
+}
+
+void QGenericEngine::connectToId(const QString &id)
+{
+ emit connectionError(id, OperationNotSupported);
+}
+
+void QGenericEngine::disconnectFromId(const QString &id)
+{
+ emit connectionError(id, OperationNotSupported);
+}
+
+void QGenericEngine::requestUpdate()
+{
+ pollTimer.stop();
+ QTimer::singleShot(0, this, SLOT(doRequestUpdate()));
+}
+
+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
+ // network configurations which will break current sessions.
+ QList<QNetworkInterface> interfaces = QNetworkInterface::allInterfaces();
+ if (interfaces.isEmpty())
+ interfaces = QNetworkInterface::allInterfaces();
+
+ QStringList previous = accessPointConfigurations.keys();
+
+ // create configuration for each interface
+ while (!interfaces.isEmpty()) {
+ QNetworkInterface interface = interfaces.takeFirst();
+
+ if (!interface.isValid())
+ continue;
+
+ // ignore loopback interface
+ if (interface.flags() & QNetworkInterface::IsLoopBack)
+ continue;
+
+ // ignore WLAN interface handled in seperate engine
+ if (qGetInterfaceType(interface.name()) == QLatin1String("WLAN"))
+ continue;
+
+ uint identifier;
+ if (interface.index())
+ identifier = qHash(QLatin1String("generic:") + QString::number(interface.index()));
+ else
+ identifier = qHash(QLatin1String("generic:") + interface.hardwareAddress());
+
+ const QString id = QString::number(identifier);
+
+ previous.removeAll(id);
+
+ QString name = interface.humanReadableName();
+ if (name.isEmpty())
+ name = interface.name();
+
+ QNetworkConfiguration::StateFlags state = QNetworkConfiguration::Discovered;
+ if (interface.flags() & QNetworkInterface::IsUp)
+ state |= QNetworkConfiguration::Active;
+
+ if (accessPointConfigurations.contains(id)) {
+ QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id);
+
+ bool changed = false;
+
+ if (!ptr->isValid) {
+ ptr->isValid = true;
+ changed = true;
+ }
+
+ if (ptr->name != name) {
+ ptr->name = name;
+ changed = true;
+ }
+
+ if (ptr->id != id) {
+ ptr->id = id;
+ changed = true;
+ }
+
+ if (ptr->state != state) {
+ ptr->state = state;
+ changed = true;
+ }
+
+ if (changed)
+ emit configurationChanged(ptr);
+ } else {
+ QNetworkConfigurationPrivatePointer ptr(new QNetworkConfigurationPrivate);
+
+ ptr->name = name;
+ ptr->isValid = true;
+ ptr->id = id;
+ ptr->state = state;
+ ptr->type = QNetworkConfiguration::InternetAccessPoint;
+ ptr->bearer = qGetInterfaceType(interface.name());
+
+ accessPointConfigurations.insert(id, ptr);
+ configurationInterface.insert(id, interface.name());
+
+ emit configurationAdded(ptr);
+ }
+ }
+
+ while (!previous.isEmpty()) {
+ QNetworkConfigurationPrivatePointer ptr =
+ accessPointConfigurations.take(previous.takeFirst());
+
+ configurationInterface.remove(ptr->id);
+ emit configurationRemoved(ptr);
+ }
+
+ pollTimer.start();
+
+ emit updateCompleted();
+}
+
+QNetworkSession::State QGenericEngine::sessionStateForId(const QString &id)
+{
+ QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id);
+
+ if (!ptr)
+ return QNetworkSession::Invalid;
+
+ if (!ptr->isValid) {
+ return QNetworkSession::Invalid;
+ } else if ((ptr->state & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) {
+ return QNetworkSession::Connected;
+ } else if ((ptr->state & QNetworkConfiguration::Discovered) ==
+ QNetworkConfiguration::Discovered) {
+ return QNetworkSession::Disconnected;
+ } else if ((ptr->state & QNetworkConfiguration::Defined) == QNetworkConfiguration::Defined) {
+ return QNetworkSession::NotAvailable;
+ } else if ((ptr->state & QNetworkConfiguration::Undefined) ==
+ QNetworkConfiguration::Undefined) {
+ return QNetworkSession::NotAvailable;
+ }
+
+ return QNetworkSession::Invalid;
+}
+
+QNetworkConfigurationManager::Capabilities QGenericEngine::capabilities() const
+{
+ return QNetworkConfigurationManager::ForcedRoaming;
+}
+
+QNetworkSessionPrivate *QGenericEngine::createSessionBackend()
+{
+ return new QNetworkSessionPrivateImpl;
+}
+
+QNetworkConfigurationPrivatePointer QGenericEngine::defaultConfiguration()
+{
+ return QNetworkConfigurationPrivatePointer();
+}
+
+QT_END_NAMESPACE
+
diff --git a/src/plugins/bearer/generic/qgenericengine.h b/src/plugins/bearer/generic/qgenericengine.h
new file mode 100644
index 0000000..cd9a976
--- /dev/null
+++ b/src/plugins/bearer/generic/qgenericengine.h
@@ -0,0 +1,92 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the plugins of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** 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 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QGENERICENGINE_H
+#define QGENERICENGINE_H
+
+#include "../qbearerengine_impl.h"
+
+#include <QMap>
+#include <QTimer>
+
+QT_BEGIN_NAMESPACE
+
+class QNetworkConfigurationPrivate;
+class QNetworkSessionPrivate;
+
+class QGenericEngine : public QBearerEngineImpl
+{
+ Q_OBJECT
+
+public:
+ QGenericEngine(QObject *parent = 0);
+ ~QGenericEngine();
+
+ QString getInterfaceFromId(const QString &id);
+ bool hasIdentifier(const QString &id);
+
+ QString bearerName(const QString &id);
+
+ void connectToId(const QString &id);
+ void disconnectFromId(const QString &id);
+
+ void requestUpdate();
+
+ QNetworkSession::State sessionStateForId(const QString &id);
+
+ QNetworkConfigurationManager::Capabilities capabilities() const;
+
+ QNetworkSessionPrivate *createSessionBackend();
+
+ QNetworkConfigurationPrivatePointer defaultConfiguration();
+
+private Q_SLOTS:
+ void doRequestUpdate();
+
+private:
+ QMap<QString, QString> configurationInterface;
+ QTimer pollTimer;
+};
+
+QT_END_NAMESPACE
+
+#endif
+