Exemple #1
0
QNetworkSession::State QGenericEngine::sessionStateForId(const QString &id)
{
    QMutexLocker locker(&mutex);

    QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id);

    if (!ptr)
        return QNetworkSession::Invalid;

    QMutexLocker configLocker(&ptr->mutex);

    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;
}
    foreach (QBearerEngine *engine, sessionEngines) {
        QHash<QString, QNetworkConfigurationPrivatePointer>::Iterator it;
        QHash<QString, QNetworkConfigurationPrivatePointer>::Iterator end;

        QMutexLocker locker(&engine->mutex);

        for (it = engine->snapConfigurations.begin(),
             end = engine->snapConfigurations.end(); it != end; ++it) {
            QNetworkConfigurationPrivatePointer ptr = it.value();

            QMutexLocker configLocker(&ptr->mutex);

            if ((ptr->state & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) {
                QNetworkConfiguration config;
                config.d = ptr;
                return config;
            } else if (!defaultConfiguration) {
                if ((ptr->state & QNetworkConfiguration::Discovered) == QNetworkConfiguration::Discovered)
                    defaultConfiguration = ptr;
            }
        }
    }
Exemple #3
0
void QIcdEngine::addConfiguration(QString& iap_id)
{
    // Note: When new IAP is created, this function gets called multiple times
    //       in a row.
    //       For example: Empty type & name for WLAN was stored into newly
    //                    created IAP data in gconf when this function gets
    //                    called for the first time.
    //                    WLAN type & name are updated into IAP data in gconf
    //                    as soon as WLAN connection is up and running.
    //                    => And this function gets called again.

    QMutexLocker locker(&mutex);

    if (!accessPointConfigurations.contains(iap_id)) {
	Maemo::IAPConf saved_iap(iap_id);
        QString iap_type = saved_iap.value("type").toString();
        QString iap_name = saved_iap.value("name").toString();
        QByteArray ssid = saved_iap.value("wlan_ssid").toByteArray();
        if (!iap_type.isEmpty() && !iap_name.isEmpty()) {
            // Check if new IAP is actually Undefined WLAN configuration
            // Note: SSID is used as an iap id for Undefined WLAN configurations
            //       => configuration must be searched using SSID
            if (!ssid.isEmpty() && accessPointConfigurations.contains(ssid)) {
                QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.take(ssid);
                if (ptr) {
                    ptr->mutex.lock();
                    ptr->id = iap_id;
                    toIcdConfig(ptr)->iap_type = iap_type;
                    ptr->bearerType = bearerTypeFromIapType(iap_type);
                    toIcdConfig(ptr)->network_attrs = getNetworkAttrs(true, iap_id, iap_type, QString());
                    toIcdConfig(ptr)->network_id = ssid;
                    toIcdConfig(ptr)->service_id = saved_iap.value("service_id").toString();
                    toIcdConfig(ptr)->service_type = saved_iap.value("service_type").toString();
                    if (m_onlineIapId == iap_id) {
                        ptr->state = QNetworkConfiguration::Active;
                    } else {
                        ptr->state = QNetworkConfiguration::Defined;
                    }
                    ptr->mutex.unlock();
                    accessPointConfigurations.insert(iap_id, ptr);

                    locker.unlock();
                    emit configurationChanged(ptr);
                    locker.relock();
                }
            } else {
                IcdNetworkConfigurationPrivate *cpPriv = new IcdNetworkConfigurationPrivate;
                cpPriv->name = saved_iap.value("name").toString();
                if (cpPriv->name.isEmpty())
                    cpPriv->name = iap_id;
                cpPriv->isValid = true;
                cpPriv->id = iap_id;
                cpPriv->iap_type = iap_type;
                cpPriv->bearerType = bearerTypeFromIapType(iap_type);
                cpPriv->network_attrs = getNetworkAttrs(true, iap_id, iap_type, QString());
                cpPriv->service_id = saved_iap.value("service_id").toString();
                cpPriv->service_type = saved_iap.value("service_type").toString();
                if (iap_type.startsWith(QLatin1String("WLAN"))) {
                    QByteArray ssid = saved_iap.value("wlan_ssid").toByteArray();
                    if (ssid.isEmpty()) {
                        qWarning() << "Cannot get ssid for" << iap_id;
                    }
                    cpPriv->network_id = ssid;
                }
                cpPriv->type = QNetworkConfiguration::InternetAccessPoint;
                if (m_onlineIapId == iap_id) {
                    cpPriv->state = QNetworkConfiguration::Active;
                } else {
                    cpPriv->state = QNetworkConfiguration::Defined;
                }

                QNetworkConfigurationPrivatePointer ptr(cpPriv);
                accessPointConfigurations.insert(iap_id, ptr);

#ifdef BEARER_MANAGEMENT_DEBUG
                qDebug("IAP: %s, name: %s, added to known list", iap_id.toAscii().data(), cpPriv->name.toAscii().data());
#endif
                locker.unlock();
                emit configurationAdded(ptr);
                locker.relock();
            }
        } else {
            qWarning("IAP %s does not have \"type\" or \"name\" fields defined, skipping this IAP.", iap_id.toAscii().data());
        }
    } else {
#ifdef BEARER_MANAGEMENT_DEBUG
	qDebug() << "IAP" << iap_id << "already in db.";
#endif

	/* Check if the data in db changed and update configuration accordingly
	 */
    QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(iap_id);
	if (ptr) {
	    Maemo::IAPConf changed_iap(iap_id);
	    QString iap_type = changed_iap.value("type").toString();
	    bool update_needed = false; /* if IAP type or ssid changed, we need to change the state */

        QMutexLocker configLocker(&ptr->mutex);

	    toIcdConfig(ptr)->network_attrs = getNetworkAttrs(true, iap_id, iap_type, QString());
	    toIcdConfig(ptr)->service_id = changed_iap.value("service_id").toString();
	    toIcdConfig(ptr)->service_type = changed_iap.value("service_type").toString();

	    if (!iap_type.isEmpty()) {
            ptr->name = changed_iap.value("name").toString();
            if (ptr->name.isEmpty())
                ptr->name = iap_id;
            ptr->isValid = true;
            if (toIcdConfig(ptr)->iap_type != iap_type) {
                toIcdConfig(ptr)->iap_type = iap_type;
                ptr->bearerType = bearerTypeFromIapType(iap_type);
                update_needed = true;
            }
            if (iap_type.startsWith(QLatin1String("WLAN"))) {
                QByteArray ssid = changed_iap.value("wlan_ssid").toByteArray();
                if (ssid.isEmpty()) {
                    qWarning() << "Cannot get ssid for" << iap_id;
                }
                if (toIcdConfig(ptr)->network_id != ssid) {
                    toIcdConfig(ptr)->network_id = ssid;
                    update_needed = true;
                }
            }
	    }

	    if (update_needed) {
            ptr->type = QNetworkConfiguration::InternetAccessPoint;
            if (m_onlineIapId == iap_id) {
                if (ptr->state < QNetworkConfiguration::Active) {
                    ptr->state = QNetworkConfiguration::Active;

                    configLocker.unlock();
                    locker.unlock();
                    emit configurationChanged(ptr);
                    locker.relock();
                }
            } else if (ptr->state < QNetworkConfiguration::Defined) {
                ptr->state = QNetworkConfiguration::Defined;

                configLocker.unlock();
                locker.unlock();
                emit configurationChanged(ptr);
                locker.relock();
            }
	    }
	} else {
	    qWarning("Cannot find IAP %s from current configuration although it should be there.", iap_id.toAscii().data());
	}
    }
}