wlanutilities/wlanqtutilities/base/src/wlanqtutils_p.cpp
changeset 56 de27cc8389dd
parent 46 2fbd1d709fe7
child 58 301aeb18ae47
--- a/wlanutilities/wlanqtutilities/base/src/wlanqtutils_p.cpp	Wed Aug 18 10:52:46 2010 +0300
+++ b/wlanutilities/wlanqtutilities/base/src/wlanqtutils_p.cpp	Thu Sep 02 21:36:44 2010 +0300
@@ -67,6 +67,7 @@
     mEsockWrapper(new WlanQtUtilsEsockWrapper(this)),
     mIctService(),
     mScanMode(ScanModeNone),
+    mIapScanList(),
     mWlanScanList(),
     mToBeTestedIapId(WlanQtUtils::IapIdNone), 
     mConnectingIapId(WlanQtUtils::IapIdNone),
@@ -76,6 +77,13 @@
 
     // Make all connections.
     bool connectStatus = connect(
+        mScanWrapper,
+        SIGNAL(availableWlanIaps(QList< QSharedPointer<WlanQtUtilsIap> > &)),
+        this,
+        SLOT(updateAvailableWlanIaps(QList< QSharedPointer<WlanQtUtilsIap> > &)));
+    Q_ASSERT(connectStatus);
+    
+    connectStatus = connect(
         mScanWrapper, 
         SIGNAL(availableWlanAps(QList< QSharedPointer<WlanQtUtilsAp> >&)), 
         this, 
@@ -145,9 +153,9 @@
     // Scanning while there is an ongoing scan is not supported
     Q_ASSERT(mScanMode == ScanModeNone);
     
-    // Just forward the request to wrapper, which triggers a broadcast WLAN scan
+    // Starting with an IAP scan, and continuing with AP scan
     mScanMode = ScanModeAvailableWlans;
-    mScanWrapper->scanWlanAps();
+    mScanWrapper->scanWlanIaps();
 
     OstTraceFunctionExit1(WLANQTUTILSPRIVATE_SCANWLANS_EXIT, this);
 }
@@ -225,19 +233,16 @@
     QList< QSharedPointer<WlanQtUtilsIap> > configuredIapList;
     mSettings->fetchIaps(configuredIapList);
 
-    // Match IAPs against WLAN scan results
-    foreach (QSharedPointer<WlanQtUtilsIap> iap, configuredIapList) {
-        foreach (QSharedPointer<WlanQtUtilsAp> scanAp, mWlanScanList) {
-            if (WlanQtUtilsAp::compare(iap.data(), scanAp.data()) == 0) {
-                // IAP found, add it to caller's list of known IAPs
-                // (signal strength needs to be updated manually since
-                // the IAP in our list does not have that information yet)
-                iap->setValue(
-                    WlanQtUtilsAp::ConfIdSignalStrength,
-                    scanAp->value(WlanQtUtilsAp::ConfIdSignalStrength));
-                wlanIapList.append(iap);
-                break;
-            }
+    // Update the list of available IAPs
+    foreach (QSharedPointer<WlanQtUtilsIap> iapIter, mIapScanList) {
+        int iapId = iapIter->value(WlanQtUtilsIap::ConfIdIapId).toInt();
+        QSharedPointer<WlanQtUtilsIap> iap(mSettings->fetchIap(iapId));
+        if (iap) {
+            // Only add the IAP if we (still) have the settings for it
+            iap->setValue(
+                WlanQtUtilsAp::ConfIdSignalStrength,
+                iapIter->value(WlanQtUtilsAp::ConfIdSignalStrength));
+            wlanIapList.append(iap);
         }
     }
 
@@ -506,7 +511,28 @@
 }
 
 /*!
-    Slot for handling WLAN scan result event from wrapper. Results are
+    Slot for handling WLAN IAP scan result event from wrapper. Results are
+    stored in a member variable.
+
+    @param [in] availableIaps Available WLAN IAP's found in scan.
+*/
+
+void WlanQtUtilsPrivate::updateAvailableWlanIaps(
+    QList< QSharedPointer<WlanQtUtilsIap> > &availableIaps)
+{
+    OstTraceFunctionEntry0(WLANQTUTILSPRIVATE_UPDATEAVAILABLEWLANIAPS_ENTRY);
+
+    // Store the new IAP list
+    mIapScanList = availableIaps;
+
+    // Continue with AP scan (which should come immediately from WLAN's scan cache)
+    mScanWrapper->scanWlanAps();
+    
+    OstTraceFunctionExit0(WLANQTUTILSPRIVATE_UPDATEAVAILABLEWLANIAPS_EXIT);
+}
+
+/*!
+    Slot for handling WLAN AP scan result event from wrapper. Results are
     stored in member variable (possible duplicates are removed).
 
     @param [in] availableWlanList WLAN networks found in scan.
@@ -519,6 +545,7 @@
 
     // Old results are removed
     mWlanScanList.clear();
+    
     // Copy available WLANs to scan result list (duplicates are removed)
     for (int i = 0; i < availableWlanList.count(); i++) {
         bool duplicate = false;
@@ -537,10 +564,10 @@
 
     // The information is forwarded to the client
     reportScanResult(WlanQtUtils::ScanStatusOk);
-    
+
     // Scan is complete
     mScanMode = ScanModeNone;
-    
+
     OstTraceFunctionExit1(WLANQTUTILSPRIVATE_UPDATEAVAILABLEWLANAPS_EXIT, this);
 }