src/plugins/bearer/icd/qnetworksession_impl.cpp
changeset 37 758a864f9613
parent 33 3e2da88830cd
--- a/src/plugins/bearer/icd/qnetworksession_impl.cpp	Fri Sep 17 08:34:18 2010 +0300
+++ b/src/plugins/bearer/icd/qnetworksession_impl.cpp	Mon Oct 04 01:19:32 2010 +0300
@@ -235,7 +235,7 @@
 }
 
 
-quint64 QNetworkSessionPrivateImpl::getStatistics(bool sent) const
+QNetworkSessionPrivateImpl::Statistics QNetworkSessionPrivateImpl::getStatistics() const
 {
     /* This could be also implemented by using the Maemo::Icd::statistics()
      * that gets the statistics data for a specific IAP. Change if
@@ -243,56 +243,51 @@
      */
     Maemo::Icd icd;
     QList<Maemo::IcdStatisticsResult> stats_results;
-    quint64 counter_rx = 0, counter_tx = 0;
+    Statistics stats = { 0, 0, 0};
 
-    if (!icd.statistics(stats_results)) {
-	return 0;
-    }
+    if (!icd.statistics(stats_results))
+        return stats;
 
     foreach (const Maemo::IcdStatisticsResult &res, stats_results) {
-	if (res.params.network_attrs & ICD_NW_ATTR_IAPNAME) {
-	    /* network_id is the IAP UUID */
-	    if (QString(res.params.network_id.data()) == activeConfig.identifier()) {
-		counter_tx = res.bytes_sent;
-		counter_rx = res.bytes_received;
-	    }
-	} else {
-	    /* We probably will never get to this branch */
-        IcdNetworkConfigurationPrivate *icdConfig =
-            toIcdConfig(privateConfiguration(activeConfig));
+        if (res.params.network_attrs & ICD_NW_ATTR_IAPNAME) {
+            /* network_id is the IAP UUID */
+            if (QString(res.params.network_id.data()) == activeConfig.identifier()) {
+                stats.txData = res.bytes_sent;
+                stats.rxData = res.bytes_received;
+                stats.activeTime = res.time_active;
+            }
+        } else {
+            /* We probably will never get to this branch */
+            IcdNetworkConfigurationPrivate *icdConfig =
+                toIcdConfig(privateConfiguration(activeConfig));
 
-        icdConfig->mutex.lock();
-        if (res.params.network_id == icdConfig->network_id) {
-            counter_tx = res.bytes_sent;
-            counter_rx = res.bytes_received;
-	    }
-        icdConfig->mutex.unlock();
-	}
+            icdConfig->mutex.lock();
+            if (res.params.network_id == icdConfig->network_id) {
+                stats.txData = res.bytes_sent;
+                stats.rxData = res.bytes_received;
+                stats.activeTime = res.time_active;
+            }
+            icdConfig->mutex.unlock();
+        }
     }
 
-    if (sent)
-	return counter_tx;
-    else
-	return counter_rx;
+    return stats;
 }
 
 
 quint64 QNetworkSessionPrivateImpl::bytesWritten() const
 {
-    return getStatistics(true);
+    return getStatistics().txData;
 }
 
 quint64 QNetworkSessionPrivateImpl::bytesReceived() const
 {
-    return getStatistics(false);
+    return getStatistics().rxData;
 }
 
 quint64 QNetworkSessionPrivateImpl::activeTime() const
 {
-    if (startTime.isNull()) {
-        return 0;
-    }
-    return startTime.secsTo(QDateTime::currentDateTime());
+    return getStatistics().activeTime;
 }
 
 
@@ -323,6 +318,7 @@
     cpPriv->purpose = fromPriv->purpose;
     cpPriv->network_id = fromPriv->network_id;
     cpPriv->iap_type = fromPriv->iap_type;
+    cpPriv->bearerType = fromPriv->bearerType;
     cpPriv->network_attrs = fromPriv->network_attrs;
     cpPriv->service_type = fromPriv->service_type;
     cpPriv->service_id = fromPriv->service_id;
@@ -343,8 +339,6 @@
     isOpen = false;
     opened = false;
 
-    connect(&manager, SIGNAL(updateCompleted()), this, SLOT(networkConfigurationsChanged()));
-
     connect(engine, SIGNAL(iapStateChanged(const QString&, uint)),
             this, SLOT(iapStateChanged(const QString&, uint)));
 
@@ -448,6 +442,7 @@
             ptr->id = toIcdConfig(ptr)->network_id;
             toIcdConfig(ptr)->network_attrs = state_results.first().params.network_attrs;
             toIcdConfig(ptr)->iap_type = state_results.first().params.network_type;
+            ptr->bearerType = bearerTypeFromIapType(toIcdConfig(ptr)->iap_type);
             toIcdConfig(ptr)->service_type = state_results.first().params.service_type;
             toIcdConfig(ptr)->service_id = state_results.first().params.service_id;
             toIcdConfig(ptr)->service_attrs = state_results.first().params.service_attrs;
@@ -463,14 +458,15 @@
 			else
                 ptr->name = ptr->id;
 
+            const QString identifier = ptr->id;
+
+            configLocker.unlock();
+
             // Add the new active configuration to manager or update the old config
-            if (!engine->hasIdentifier(ptr->id)) {
-                configLocker.unlock();
+            if (!engine->hasIdentifier(identifier))
                 engine->addSessionConfiguration(ptr);
-            } else {
-                configLocker.unlock();
+            else
                 engine->changedSessionConfiguration(ptr);
-            }
         }
         break;
 
@@ -824,6 +820,7 @@
             icdConfig->name = name;
 
         icdConfig->iap_type = rep.arguments().at(3).toString(); // connect_result.connect.network_type;
+        icdConfig->bearerType = bearerTypeFromIapType(icdConfig->iap_type);
         icdConfig->isValid = true;
         icdConfig->state = QNetworkConfiguration::Active;
         icdConfig->type = QNetworkConfiguration::InternetAccessPoint;
@@ -891,12 +888,12 @@
 	    state = QNetworkSession::Closing;
 	    emit stateChanged(state);
 
+	    // we fake a disconnection, session error is sent
+	    updateState(QNetworkSession::Disconnected);
+
 	    opened = false;
 	    isOpen = false;
 
-	    // we fake a disconnection, session error is not sent
-	    updateState(QNetworkSession::Disconnected);
-
 	    icd.disconnect(ICD_CONNECTION_FLAG_APPLICATION_EVENT);
 	    startTime = QDateTime();
         } else {